@php
    $groupAccount = $group['account'];
    $groupEntries = $group['entries'] ?? collect();
    $groupTotals = $group['totals'] ?? [];
    $accountTitle = $groupAccount->code ? '[' . $groupAccount->code . '] ' . $groupAccount->name : $groupAccount->name;
@endphp
<tr class="gl-account-header-row">
    <td colspan="9">
        <a href="{{ route('reports.general-ledger', array_merge(
            request()->only(['date_from', 'date_to', 'account_sections', 'voucher_types', 'dimension_value_ids', 'search']),
            ['account_ids' => [$groupAccount->id]]
        )) }}" class="text-decoration-none fw-bold gl-account-header-link">
            {{ $accountTitle }}
        </a>
    </td>
</tr>
<tr class="gl-report-opening-row">
    <td>{{ \Carbon\Carbon::parse($dateFrom)->subDay()->format('d M Y') }}</td>
    <td></td>
    <td class="fw-semibold">Opening Balance</td>
    <td></td>
    <td></td>
    <td></td>
    <td class="text-end">{{ $fmt($groupTotals['opening_debit'] ?? 0) }}</td>
    <td class="text-end">{{ $fmt($groupTotals['opening_credit'] ?? 0) }}</td>
    <td class="text-end fw-semibold">
        {{ ($groupTotals['opening_debit'] ?? 0) > 0 ? $fmt($groupTotals['opening_debit']) . ' Dr' : (($groupTotals['opening_credit'] ?? 0) > 0 ? $fmt($groupTotals['opening_credit']) . ' Cr' : '—') }}
    </td>
</tr>
@foreach($groupEntries as $entry)
    @include('reports.general-ledger._entry-row', ['entry' => $entry, 'fmt' => $fmt])
@endforeach
<tr class="gl-account-total-row">
    <td colspan="6" class="text-end fw-semibold">Total {{ $groupAccount->name }}</td>
    <td class="text-end fw-semibold">{{ $fmt($groupTotals['period_debit'] ?? 0) }}</td>
    <td class="text-end fw-semibold">{{ $fmt($groupTotals['period_credit'] ?? 0) }}</td>
    <td class="text-end fw-semibold">
        {{ ($groupTotals['closing_debit'] ?? 0) > 0 ? $fmt($groupTotals['closing_debit']) . ' Dr' : (($groupTotals['closing_credit'] ?? 0) > 0 ? $fmt($groupTotals['closing_credit']) . ' Cr' : '—') }}
    </td>
</tr>
<tr class="gl-account-spacer-row"><td colspan="9"></td></tr>
