@extends('adminlte::page')

@section('title', 'Senarai Semakan Pengesahan')

@section('content_header')
    <h1><i class="fas fa-clipboard-check mr-2"></i>Senarai Semakan Pengesahan</h1>
@stop

@section('content')
    @if (session('success'))
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <i class="fas fa-check-circle mr-2"></i>{{ session('success') }}
        </div>
    @endif

    {{-- Pilihan Tahun --}}
    <div class="d-flex align-items-center mb-3">
        <label class="mr-2 mb-0 font-weight-bold"><i class="fas fa-calendar-alt mr-1"></i>Tahun:</label>
        <form method="GET" action="{{ route('checker.pengesahan.index') }}" class="d-flex" id="formTahun">
            <select name="tahun" class="form-control form-control-sm mr-2" style="width:auto"
                onchange="this.form.submit()">
                @for ($y = 2026; $y <= 2040; $y++)
                    <option value="{{ $y }}" {{ $tahun == $y ? 'selected' : '' }}>{{ $y }}</option>
                @endfor
            </select>
        </form>
    </div>

    {{-- Jadual Senarai --}}
    <div class="card card-outline card-primary">
        <div class="card-header">
            <h3 class="card-title"><i class="fas fa-list mr-1"></i> Senarai Pengesahan Tahun {{ $tahun }}</h3>
        </div>
        <div class="card-body p-0">
            @if ($pengesahans->isEmpty())
                <div class="text-center py-5 text-muted">
                    <i class="fas fa-inbox fa-3x mb-3"></i>
                    <p>Tiada pengesahan dihantar untuk tahun {{ $tahun }}.</p>
                </div>
            @else
                <table class="table table-hover table-striped mb-0">
                    <thead class="thead-light">
                        <tr>
                            <th>#</th>
                            <th>Nama Pemohon</th>
                            <th>Kod Sekolah</th>
                            <th>Nama Sekolah</th>
                            <th>Jenis Sekolah</th>
                            <th class="text-center">Tarikh Hantar</th>
                            <th class="text-center">Status</th>
                            <th class="text-center">Tindakan</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($pengesahans as $i => $p)
                            <tr>
                                <td>{{ $i + 1 }}</td>
                                <td>{{ $p->user->name ?? '-' }}</td>
                                <td><span class="badge badge-primary">{{ $p->kod_sekolah }}</span></td>
                                <td>{{ $p->user->nama_sekolah ?? '-' }}</td>
                                <td><span class="badge badge-info">{{ $p->jenis_sekolah ?? '-' }}</span></td>
                                <td class="text-center">
                                    {{ $p->dihantar_pada ? $p->dihantar_pada->format('d/m/Y H:i') : '-' }}
                                </td>
                                <td class="text-center">
                                    @if ($p->status === 'belum_semak')
                                        <span class="badge badge-warning">Belum Disemak</span>
                                    @elseif ($p->status === 'lulus')
                                        <span class="badge badge-success">Diluluskan</span>
                                    @elseif ($p->status === 'ditolak')
                                        <span class="badge badge-danger">Ditolak</span>
                                    @endif
                                </td>
                                <td class="text-center">
                                    <a href="{{ route('checker.pengesahan.show', $p->id) }}" class="btn btn-sm btn-info">
                                        <i class="fas fa-eye mr-1"></i>Semak
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            @endif
        </div>
    </div>
@stop
