{{define "content"}}
<div class="space-y-6">
    <div class="sm:flex sm:items-center sm:justify-between">
        <h1 class="text-2xl font-bold text-gray-900">Trial Balance</h1>
        <div class="flex space-x-3">
            <a href="/ledger/accounts" class="text-sm text-indigo-600 hover:text-indigo-500">Chart of Accounts</a>
            <a href="/ledger/journal" class="text-sm text-indigo-600 hover:text-indigo-500">Journal Entries</a>
        </div>
    </div>

    <div class="overflow-hidden bg-white shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
        <table class="min-w-full divide-y divide-gray-300">
            <thead class="bg-gray-50">
                <tr>
                    <th class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900">Code</th>
                    <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Account Name</th>
                    <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Type</th>
                    <th class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900">Debit</th>
                    <th class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900">Credit</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-200 bg-white">
                {{range .Rows}}
                {{if or (gt .Debit 0.0) (gt .Credit 0.0)}}
                <tr class="hover:bg-gray-50">
                    <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-mono font-medium text-gray-900">{{.Code}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">{{.Name}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm">{{accountTypeBadge .Type}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900 text-right font-mono">
                        {{if gt .Debit 0.0}}{{formatMoney .Debit}}{{else}}-{{end}}
                    </td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900 text-right font-mono">
                        {{if gt .Credit 0.0}}{{formatMoney .Credit}}{{else}}-{{end}}
                    </td>
                </tr>
                {{end}}
                {{end}}
            </tbody>
            <tfoot>
                <tr class="bg-gray-50 border-t-2 border-gray-900">
                    <td colspan="3" class="py-4 pl-4 pr-3 text-sm font-semibold text-gray-900">Totals</td>
                    <td class="px-3 py-4 text-sm font-semibold text-gray-900 text-right font-mono">{{formatMoney .TotalDebit}}</td>
                    <td class="px-3 py-4 text-sm font-semibold text-gray-900 text-right font-mono">{{formatMoney .TotalCredit}}</td>
                </tr>
                <tr class="bg-gray-50">
                    <td colspan="3" class="py-2 pl-4 pr-3 text-sm text-gray-500">Difference (should be $0.00)</td>
                    <td colspan="2" class="px-3 py-2 text-sm text-right font-mono {{if eq .TotalDebit .TotalCredit}}text-green-600{{else}}text-red-600 font-bold{{end}}">
                        {{formatMoney (sub .TotalDebit .TotalCredit)}}
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>

    {{if not .Rows}}
    <div class="text-center py-8 text-sm text-gray-500">
        No transactions recorded yet. The trial balance will populate as journal entries are created.
    </div>
    {{end}}
</div>
{{end}}
