@extends('adminlte::page')

@section('title', "Detail Pesanan Buku — {{ $darjah }}")

@section('content_header')
    <h1><i class="fas fa-book-open mr-2"></i>Detail Pesanan Buku — {{ $darjah }}</h1>
@stop

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

    <h5 class="text-muted mb-3">
        <i class="fas fa-school mr-1"></i> Senarai Sekolah Yang Pesan Buku ({{ $darjah }})
        — Daerah: <span class="badge badge-primary">{{ $daerah }}</span>
        — Tahun: <span class="badge badge-info">{{ $tahun }}</span>
    </h5>

    @if ($senarai->isEmpty())
        <div class="card">
            <div class="card-body text-center text-muted py-4">
                <i class="fas fa-info-circle mr-1"></i> Tiada sekolah yang membuat pesanan buku untuk {{ $darjah }}.
            </div>
        </div>
    @else
        {{-- Jadual Ringkasan --}}
        <div class="card card-outline card-primary mb-3">
            <div class="card-header">
                <h3 class="card-title"><i class="fas fa-list-ol mr-1"></i> Ringkasan Pesanan</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 Pesanan</th>
                            <th class="text-center">Tindakan</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($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">{{ number_format($item['total_pesanan']) }}</td>
                                <td class="text-center">
                                    <a href="{{ route('supervisor.lihat-buku', $user->id) }}?darjah={{ $darjah }}&from=laporan-buku"
                                        class="btn btn-info btn-sm">
                                        <i class="fas fa-eye mr-1"></i>Detail
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>

    @endif
@stop
