@extends('layouts.admin')

@section('title', 'Absensi Siswa')
@section('subtitle', 'Rekap kehadiran siswa per hari')

@section('content')

{{-- Rekap hari ini --}}
<div class="row g-3 mb-4">
    @php
        $rekapItems = [
            ['label' => 'Hadir',     'key' => 'hadir', 'color' => '#155724', 'bg' => '#d4edda', 'icon' => 'circle-check'],
            ['label' => 'Sakit',     'key' => 'sakit', 'color' => '#856404', 'bg' => '#fff3cd', 'icon' => 'face-dizzy'],
            ['label' => 'Izin',      'key' => 'izin',  'color' => '#0c5460', 'bg' => '#d1ecf1', 'icon' => 'envelope'],
            ['label' => 'Alfa',      'key' => 'alfa',  'color' => '#721c24', 'bg' => '#f8d7da', 'icon' => 'ban'],
            ['label' => 'Blm Absen', 'key' => 'belum', 'color' => '#383d41', 'bg' => '#e2e3e5', 'icon' => 'clock'],
        ];
    @endphp
    @foreach($rekapItems as $item)
        <div class="col-6 col-lg">
            <div class="stat-card">
                <div>
                    <div class="label">{{ $item['label'] }}</div>
                    <div class="value">{{ $rekap[$item['key']] ?? 0 }}</div>
                    <div class="delta text-muted">siswa</div>
                </div>
                <div class="stat-icon" style="background:{{ $item['bg'] }};color:{{ $item['color'] }};">
                    <i class="fa-solid fa-{{ $item['icon'] }}"></i>
                </div>
            </div>
        </div>
    @endforeach
</div>

<div class="panel">
    <div class="panel-head">
        <h3>Detail Absensi Siswa</h3>
        <form method="GET" class="d-flex align-items-center gap-2">
            <select name="kelas" class="form-select form-select-sm" style="width:auto;" onchange="this.form.submit()">
                <option value="">Semua Kelas</option>
                @foreach($semuaKelas as $kelas)
                    <option value="{{ $kelas }}" {{ $filterKelas === $kelas ? 'selected' : '' }}>Kelas {{ $kelas }}</option>
                @endforeach
            </select>
            <input type="date" name="tanggal" class="form-control form-control-sm" value="{{ $tanggal }}"
                max="{{ today()->format('Y-m-d') }}" onchange="this.form.submit()">
        </form>
    </div>
    <div class="table-responsive">
        <table class="table-modern">
            <thead>
                <tr>
                    <th>Nama Siswa</th>
                    <th>NIS</th>
                    <th>Kelas</th>
                    <th>Status</th>
                    <th>Keterangan</th>
                    <th>Dicatat oleh</th>
                </tr>
            </thead>
            <tbody>
                @forelse($students as $s)
                    <tr>
                        <td class="fw-semibold">{{ $s->name }}</td>
                        <td class="text-muted">{{ $s->nis }}</td>
                        <td>{{ $s->class }}</td>
                        <td>
                            @if($s->absen)
                                <span class="badge badge-{{ $s->absen->status }}">
                                    {{ \App\Models\StudentAttendance::statusLabel($s->absen->status) }}
                                </span>
                            @else
                                <span class="badge badge-belum">Belum</span>
                            @endif
                        </td>
                        <td class="text-muted">{{ $s->absen?->notes ?? '-' }}</td>
                        <td class="text-muted">{{ $s->absen?->recorder?->name ?? '-' }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="text-center text-muted py-4">Tidak ada data siswa.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

@endsection
