@extends('adminlte::page')

@section('title', 'Senarai Sekolah KKM — Buku Rosak')

@section('content_header')
    <h1><i class="fas fa-mosque mr-2"></i>Senarai Sekolah KKM — Buku Rosak</h1>
@stop

@section('content')
    <div class="mb-3">
        <a href="{{ route('supervisor.laporan.kkm-buku-rosak') }}" class="btn btn-outline-secondary btn-sm">
            <i class="fas fa-arrow-left mr-1"></i> Kembali ke Laporan Buku Rosak KKM
        </a>
    </div>

    <div class="d-flex justify-content-between align-items-center mb-3">
        <h5 class="text-muted mb-0">
            <i class="fas fa-list-ol mr-1"></i> Senarai Sekolah KKM Yang Ada Buku Rosak
            — Daerah: <span class="badge badge-primary">{{ $daerah }}</span>
        </h5>
        <form method="GET" action="{{ route('supervisor.laporan.kkm-senarai-sekolah-rosak') }}" class="form-inline">
            <label class="mr-2 text-muted"><i class="fas fa-calendar-alt mr-1"></i>Tahun:</label>
            <select name="tahun" class="form-control form-control-sm" onchange="this.form.submit()">
                @foreach ($senarai_tahun as $t)
                    <option value="{{ $t }}" {{ $t == $tahun ? 'selected' : '' }}>{{ $t }}</option>
                @endforeach
            </select>
        </form>
    </div>

    <div class="card card-outline card-danger">
        <div class="card-header">
            <h3 class="card-title"><i class="fas fa-book-dead mr-1"></i> Ringkasan Buku Rosak KKM — Tahun
                {{ $tahun }}</h3>
        </div>
        <div class="card-body p-0">
            <table class="table table-hover table-striped mb-0">
                <thead class="thead-light">
                    <tr>
                        <th>Bil</th>
                        <th>Nama Sekolah</th>
                        <th>Kod Sekolah</th>
                        <th class="text-center">Jumlah Buku Rosak</th>
                        <th class="text-center">Tindakan</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($senarai as $i => $item)
                        @php $user = $item['user']; @endphp
                        <tr>
                            <td>{{ $i + 1 }}</td>
                            <td>{{ $user->nama_sekolah ?? '-' }}</td>
                            <td><span class="badge badge-primary">{{ $user->kod_sekolah ?? '-' }}</span></td>
                            <td class="text-center font-weight-bold text-danger">
                                {{ number_format($item['total_rosak']) }}
                            </td>
                            <td class="text-center">
                                <a href="{{ route('supervisor.laporan.buku-rosak-detail', $user->id) }}?from=kkm-senarai-sekolah-rosak"
                                    class="btn btn-danger btn-sm">
                                    <i class="fas fa-eye mr-1"></i>Detail
                                </a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">
                                <i class="fas fa-info-circle mr-1"></i> Tiada sekolah KKM dengan buku rosak untuk tahun
                                {{ $tahun }}.
                            </td>
                        </tr>
                    @endforelse
                </tbody>
                @if ($senarai->isNotEmpty())
                    <tfoot class="thead-light">
                        <tr>
                            <th colspan="3" class="text-right">Jumlah Keseluruhan:</th>
                            <th class="text-center text-danger">{{ number_format($senarai->sum('total_rosak')) }}</th>
                            <th></th>
                        </tr>
                    </tfoot>
                @endif
            </table>
        </div>
    </div>
@stop
