@foreach($nodes as $node)
@php
    $hasChildren = !empty($node->children_tree);
    $indent = 12 + ($level * 20);
    $accountLabel = trim(($node->code ? $node->code . ' ' : '') . $node->name);
@endphp
<tr class="pl-tree-row"
    data-account-id="{{ $node->id }}"
    data-parent="{{ $node->parent_id ?? '' }}"
    data-level="{{ $level }}">
    <td style="padding-left:{{ $indent }}px">
        <div class="d-flex align-items-center gap-1">
            @if($hasChildren)
                <button type="button"
                        class="pl-tree-toggle btn btn-link p-0 border-0 lh-1 flex-shrink-0"
                        aria-expanded="true"
                        aria-label="Toggle {{ $accountLabel }}">
                    <i class="bi bi-chevron-down" style="font-size:11px"></i>
                </button>
            @else
                <span class="pl-tree-spacer" aria-hidden="true"></span>
            @endif

            @if($node->is_group)
                <span class="pl-report-account-label">{{ $accountLabel }}</span>
            @else
                <a href="{{ route('reports.general-ledger', array_merge(['account_id' => $node->id], $dateQuery)) }}" class="pl-report-account-link">
                    {{ $accountLabel }}
                </a>
            @endif
        </div>
    </td>
    @include('reports.profit-loss._period-amount-cells', [
        'amounts' => !empty($columnPeriods) ? ($node->report_period_amounts ?? []) : $node->report_amount,
        'total' => $node->report_amount,
        'cellClass' => $hasChildren ? 'fw-semibold' : '',
    ])
</tr>
@if($hasChildren)
    @include('reports.profit-loss._account-tree', ['nodes' => $node->children_tree, 'level' => $level + 1])
@endif
@endforeach
