<div>
    <x-title>
        CPF Status Report
        <x-slot:buttons>
            <button wire:click="$refresh" class="btn btn-outline-secondary btn-sm">
                <i class="mdi mdi-sync"></i>
            </button>
        </x-slot:buttons>
    </x-title>

    <div class="container-sm">

        {{-- TYPE TABS --}}
        <div class="card shadow-sm border-0 mb-4">
            <div class="card-body p-0">
                <div class="d-flex border-bottom">
                    @foreach(\App\Components\PensionCase\StatusReport::TYPES as $key => $label)
                        @php $total = $totals[$key] ?? 0; @endphp
                        <button wire:click="setType('{{ $key }}')"
                                class="btn btn-link text-decoration-none px-4 py-3 border-0 rounded-0 fw-semibold
                                       {{ $claimType === $key ? 'border-bottom border-primary border-2 text-primary' : 'text-muted' }}"
                                style="{{ $claimType === $key ? 'margin-bottom: -1px;' : '' }}">
                            {{ $label }}
                            <span class="badge ms-1 {{ $claimType === $key ? 'bg-primary' : 'bg-secondary' }}">
                                {{ number_format($total) }}
                            </span>
                        </button>
                    @endforeach
                </div>
            </div>
        </div>

        {{-- STATUS TABLE --}}
        <div class="card shadow-sm border-0">
            <div class="card-header bg-white border-bottom d-flex align-items-center gap-2 py-3">
                <span class="badge bg-info text-dark text-uppercase fs-6">{{ strtoupper($claimType) }}</span>
                <span class="fw-semibold">Status Breakdown</span>
            </div>
            <div class="card-body p-0">
                <div wire:loading wire:target="setType" class="p-4 text-center text-muted">
                    <span class="spinner-border spinner-border-sm me-2"></span> Loading...
                </div>
                <div wire:loading.remove wire:target="setType">
                    <div class="table-responsive">
                        <table class="table table-hover align-middle mb-0">
                            <thead class="table-light">
                            <tr>
                                <th class="ps-4 py-3 border-0">Status</th>
                                <th class="text-center border-0" style="width:120px">Cases</th>
                                <th class="pe-4 text-end border-0" style="width:80px">View</th>
                            </tr>
                            </thead>
                            <tbody>
                            @forelse($statusCounts as $status)
                                <tr>
                                    <td class="ps-4">
                                        <span class="fw-semibold text-dark">{{ $status->display_name }}</span>
                                    </td>
                                    <td class="text-center">
                                        @if($status->cases_count > 0)
                                            <span class="badge bg-primary rounded-pill fs-6 px-3">
                                                {{ number_format($status->cases_count) }}
                                            </span>
                                        @else
                                            <span class="text-muted">0</span>
                                        @endif
                                    </td>
                                    <td class="pe-4 text-end">
                                        @if($status->cases_count > 0)
                                            <a href="{{ route('pension-cases.index', ['status_id' => $status->id]) }}"
                                               class="btn btn-sm btn-outline-primary">
                                                <i class="mdi mdi-arrow-right"></i>
                                            </a>
                                        @endif
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="3" class="text-center py-5 text-muted">
                                        <i class="mdi mdi-folder-open d-block mb-2 fs-2"></i>
                                        No statuses configured for {{ strtoupper($claimType) }}.
                                    </td>
                                </tr>
                            @endforelse
                            @if($noStatusCount > 0)
                                <tr class="table-warning">
                                    <td class="ps-4 fst-italic text-muted">No status assigned</td>
                                    <td class="text-center fw-bold">{{ number_format($noStatusCount) }}</td>
                                    <td></td>
                                </tr>
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
