@extends('layouts.app')
@section('title', 'Permits & Renewals')
@use(App\Support\Expiry)
@section('content')
<div class="card">
    <div class="card-header pb-0">
        <h6 class="mb-2">Expiry Tracker</h6>
        <ul class="nav nav-pills nav-fill flex-column flex-sm-row mb-3" style="max-width:520px">
            @foreach(['passport'=>'Passports','permit'=>'Permits','fomema'=>'FOMEMA'] as $t=>$lbl)
                <li class="nav-item"><a class="nav-link text-sm {{ $type===$t?'active bg-gradient-primary text-white':'' }}" href="{{ route('renewals.index', ['type'=>$t,'days'=>$days]) }}">{{ $lbl }}</a></li>
            @endforeach
        </ul>
        <form method="GET" class="d-flex gap-2 align-items-center mb-2">
            <input type="hidden" name="type" value="{{ $type }}">
            <label class="text-xs mb-0">Window:</label>
            <select name="days" class="form-select form-select-sm" style="width:auto" onchange="this.form.submit()">
                @foreach([30,60,90,180] as $d)<option value="{{ $d }}" @selected($days==$d)>{{ $d }} days</option>@endforeach
            </select>
        </form>
    </div>
    <div class="card-body">
        <div class="table-responsive"><table class="table align-items-center mb-0">
            <thead><tr class="text-xxs text-uppercase text-secondary"><th class="ps-2">Name</th><th>Passport</th><th>Site</th><th>Expiry</th><th>Status</th><th></th></tr></thead>
            <tbody>
            @forelse($staff as $s)
                <tr>
                    <td class="ps-2"><a href="{{ route('staff.show', $s) }}" class="font-weight-bold text-sm">{{ $s->name }}</a></td>
                    <td class="text-sm">{{ $s->passport_no ?? '—' }}</td>
                    <td class="text-sm">{{ $s->site?->name ?? '—' }}</td>
                    <td class="text-sm">{{ optional($s->$col)->format('d M Y') }}</td>
                    <td>{!! Expiry::chip($s->$col) !!}</td>
                    <td class="text-end pe-2"><a href="{{ route('staff.show', $s) }}" class="btn btn-sm btn-outline-primary mb-0 py-1">Renew</a></td>
                </tr>
            @empty
                <tr><td colspan="6" class="text-center text-muted py-4">Nothing expiring within {{ $days }} days.</td></tr>
            @endforelse
            </tbody>
        </table></div>
        <div class="mt-3">{{ $staff->links() }}</div>
    </div>
</div>
@endsection
