<div>
    <x-title>
        Pension Cases

        @can('pension-cases.create')
            <x-slot:buttons>
                <a href="{{ route('pension-cases.create') }}" class="btn btn-success waves-effect waves-light">
                    <i class="mdi mdi-plus me-2"></i> New Pension Case
                </a>
            </x-slot:buttons>
        @endcan
    </x-title>

    <div class="row">
        {{-- MAIN TABLE --}}
        <div class="col-12 col-md-9">
            <div class="card shadow-sm">
                <div class="card-body">

                    {{-- CONTROLS --}}
                    <div class="row align-items-end mb-3 g-2">
                        <div class="col-12 col-md-4">
                            <label class="form-label">Search</label>
                            <input class="form-control"
                                   wire:model.live.debounce.300ms="search"
                                   placeholder="Case #, NI, client name, reference…">
                        </div>
                        <div class="col-6 col-md-2">
                            <label class="form-label">Status</label>
                            <select class="form-select" wire:model.live="status">
                                <option value="all">All</option>
                                <option value="open">Open</option>
                                <option value="closed">Closed</option>
                            </select>
                        </div>
                        <div class="col-6 col-md-2">
                            <label class="form-label">Vulnerable</label>
                            <select class="form-select" wire:model.live="vulnerable">
                                <option value="">Any</option>
                                <option value="1">Vulnerable</option>
                            </select>
                        </div>
                        <div class="col-6 col-md-2">
                            <label class="form-label">Per Page</label>
                            <select class="form-select" wire:model.live="perPage">
                                <option value="25">25</option>
                                <option value="50">50</option>
                                <option value="100">100</option>
                            </select>
                        </div>
                    </div>

                    {{-- TABLE --}}
                    <div class="table-responsive">
                        <table class="table table-centered table-striped table-nowrap mb-0">
                            <thead class="table-light">
                            <tr>
                                <th>Case #</th>
                                <th>Client</th>
                                <th>Owner</th>
                                <th>Settlement Status</th>
                                <th>Bank / FOS / FSCS</th>
                                <th>Status</th>
                                <th class="text-end"></th>
                            </tr>
                            </thead>
                            <tbody>
                            @forelse($cases as $case)
                                <tr>
                                    <td>
                                        <strong>{{ $case->case_number ?? $case->displayId }}</strong>
                                        @if($case->sf_case_id)
                                            <div class="text-muted small">{{ $case->sf_case_id }}</div>
                                        @endif
                                        @if($case->vulnerable_client_flag)
                                            <span class="badge bg-danger ms-1" title="Vulnerable client">V</span>
                                        @endif
                                    </td>
                                    <td>
                                        @if($case->client)
                                            <a href="{{ route('clients.show', $case->client) }}" class="text-dark">
                                                {{ $case->client->name_first }} {{ $case->client->name_last }}
                                            </a>
                                        @else
                                            <span class="text-muted">Unknown</span>
                                        @endif
                                    </td>
                                    <td>{{ $case->case_owner ?? '—' }}</td>
                                    <td>{{ $case->settlement_status ?? '—' }}</td>
                                    <td class="small">
                                        <div>Bank: {{ $case->bank_claim_status ?? '—' }}</div>
                                        <div>FOS: {{ $case->fos_claim_status ?? '—' }}</div>
                                        <div>FSCS: {{ $case->fscs_claim_status ?? '—' }}</div>
                                    </td>
                                    <td>
                                        @if($case->is_open)
                                            <span class="badge bg-success">Open</span>
                                        @else
                                            <span class="badge bg-secondary">Closed</span>
                                        @endif
                                    </td>
                                    <td class="text-end">
                                        <a href="{{ route('pension-cases.view', $case) }}"
                                           class="text-secondary me-2" title="View">
                                            <i class="mdi mdi-eye"></i>
                                        </a>
                                        @can('edit', $case)
                                            <a href="{{ route('pension-cases.edit', $case) }}"
                                               class="text-primary" title="Edit">
                                                <i class="mdi mdi-pencil"></i>
                                            </a>
                                        @endcan
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="7" class="text-center text-muted py-4">
                                        No pension cases found.
                                    </td>
                                </tr>
                            @endforelse
                            </tbody>
                        </table>
                    </div>

                    <div class="mt-3">
                        {{ $cases->links() }}
                    </div>
                </div>
            </div>
        </div>

        {{-- FILTERS SIDEBAR --}}
        <div class="col-12 col-md-3">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h5 class="card-title mb-3">Filters</h5>

                    <div class="mb-3">
                        <label class="form-label">Settlement Status</label>
                        <input class="form-control form-control-sm"
                               wire:model.live.debounce.300ms="settlementStatus"
                               placeholder="e.g. Settled">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Bank Status</label>
                        <input class="form-control form-control-sm"
                               wire:model.live.debounce.300ms="bankStatus"
                               placeholder="Bank claim status">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">FOS Status</label>
                        <input class="form-control form-control-sm"
                               wire:model.live.debounce.300ms="fosStatus"
                               placeholder="FOS status">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">FSCS Status</label>
                        <input class="form-control form-control-sm"
                               wire:model.live.debounce.300ms="fscsStatus"
                               placeholder="FSCS status">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Priority</label>
                        <input class="form-control form-control-sm"
                               wire:model.live.debounce.300ms="priority"
                               placeholder="Priority">
                    </div>

                    <button class="btn btn-sm btn-outline-secondary w-100"
                            wire:click="$set('search', ''); $set('status', 'all'); $set('settlementStatus', ''); $set('bankStatus', ''); $set('fosStatus', ''); $set('fscsStatus', ''); $set('priority', ''); $set('vulnerable', '')">
                        Clear Filters
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
