<div class="table-responsive">
    <table class="table table-hover mb-0">
        <thead class="table-light">
            <tr>
                <th style="width:48px">SL</th>
                @foreach($visibleColumns as $columnKey)
                    <th @class(['text-end' => $columnKey === 'amount'])>
                        {{ $columnLabels[$columnKey] ?? ucfirst(str_replace('_', ' ', $columnKey)) }}
                    </th>
                @endforeach
                @if($showActions ?? false)
                    <th class="text-end pe-3" style="width:110px">Action</th>
                @endif
            </tr>
        </thead>
        <tbody>
            @forelse($rows as $row)
            <tr>
                <td class="text-muted">{{ $row['serial'] }}</td>
                @foreach($visibleColumns as $columnKey)
                    <td @class([
                        'text-end fw-semibold' => $columnKey === 'amount',
                        'text-muted' => in_array($columnKey, ['account_no', 'reference', 'narration'], true),
                        'fw-semibold' => $columnKey === 'cheque_no',
                    ]) style="{{ in_array($columnKey, ['account_no'], true) ? 'font-size:12.5px' : '' }}">
                        @if($columnKey === 'voucher_number' && ($linkVoucher ?? false))
                            <a href="{{ route('vouchers.show', [$row['voucher_type'], $row['id']]) }}" class="text-decoration-none">
                                {{ $row['cells'][$columnKey] }}
                            </a>
                        @elseif($columnKey === 'status')
                            @if($row['status'] === 'void')
                                <span class="badge" style="background:#f8d7da;color:#842029">{{ $row['cells'][$columnKey] }}</span>
                            @else
                                <span class="badge" style="background:#d1e7dd;color:#0a3622">{{ $row['cells'][$columnKey] }}</span>
                            @endif
                        @else
                            {{ $row['cells'][$columnKey] }}
                        @endif
                    </td>
                @endforeach
                @if($showActions ?? false)
                    <td class="text-end pe-2">
                        <div class="dropdown">
                            <button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                Action
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end">
                                @if($row['can_print'] && ($formats ?? collect())->isNotEmpty())
                                <li>
                                    <button type="button" class="dropdown-item print-cheque-action"
                                            data-bs-toggle="modal" data-bs-target="#printChequeModal"
                                            data-voucher-id="{{ $row['id'] }}"
                                            data-cheque-no="{{ $row['cheque_no'] }}">
                                        <i class="bi bi-printer me-2"></i>Print
                                    </button>
                                </li>
                                @endif
                                @if($row['can_void'])
                                <li>
                                    <form method="POST" action="{{ route('banking.issued-void-cheques.void', $row['id']) }}"
                                          onsubmit="return confirm('Void cheque {{ $row['cheque_no'] }}?');">
                                        @csrf
                                        <button type="submit" class="dropdown-item text-danger">
                                            <i class="bi bi-x-circle me-2"></i>Void
                                        </button>
                                    </form>
                                </li>
                                @endif
                            </ul>
                        </div>
                    </td>
                @endif
            </tr>
            @empty
            <tr>
                <td colspan="{{ count($visibleColumns) + 1 + (($showActions ?? false) ? 1 : 0) }}" class="text-center text-muted py-5">
                    No cheques found for the selected filters.
                </td>
            </tr>
            @endforelse
        </tbody>
    </table>
</div>
