{% extends 'base.html' %}
{% load i18n %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-1">
                    <li class="breadcrumb-item"><a href="{% url 'accounting_dashboard' %}">{% trans "Accounting" %}</a></li>
                    <li class="breadcrumb-item"><a href="{% url 'chart_of_accounts' %}">{% trans "Chart of Accounts" %}</a></li>
                    <li class="breadcrumb-item active">{% trans "Ledger" %}</li>
                </ol>
            </nav>
            <h2 class="mb-0">
                {% trans "Ledger" %}: 
                {% if LANGUAGE_CODE == 'ar' %}{{ account.name_ar }}{% else %}{{ account.name_en }}{% endif %}
                <small class="text-muted">({{ account.code }})</small>
            </h2>
        </div>
        <div class="text-end">
            <h4 class="mb-0 text-primary">
                {% trans "Current Balance" %}: {{ total_balance|floatformat:global_settings.decimal_places }} {{ global_settings.currency_symbol }}
            </h4>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th>{% trans "Date" %}</th>
                        <th>{% trans "Reference" %}</th>
                        <th>{% trans "Description" %}</th>
                        <th class="text-end">{% trans "Debit" %}</th>
                        <th class="text-end">{% trans "Credit" %}</th>
                        <th class="text-end">{% trans "Balance" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item_data in ledger_items %}
                    <tr>
                        <td>{{ item_data.item.entry.date }}</td>
                        <td><code>{{ item_data.item.entry.reference }}</code></td>
                        <td>{{ item_data.item.entry.description }}</td>
                        <td class="text-end text-success">
                            {% if item_data.item.type == 'debit' %}{{ item_data.item.amount|floatformat:global_settings.decimal_places }}{% endif %}
                        </td>
                        <td class="text-end text-danger">
                            {% if item_data.item.type == 'credit' %}{{ item_data.item.amount|floatformat:global_settings.decimal_places }}{% endif %}
                        </td>
                        <td class="text-end fw-bold">
                            {{ item_data.balance|floatformat:global_settings.decimal_places }}
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center py-4 text-muted">{% trans "No transactions found for this account." %}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
