@extends('admin.layout')

@section('title', '')

@section('content')
    @php
        $activePeriode = \App\Models\Periode::where('status', \App\Models\Periode::STATUS_AKTIF)->first();
        $tahunPel = $activePeriode->tahun_pelajaran ?? '-';
        $semester = $activePeriode->semester ?? '-';
    @endphp
    <section class="card">
        <div class="card-header" style="background-color:#6f42c1; color:#fff;">
            <div>
                <h5 class="mb-0"><i class="bi bi-list-check me-2"></i> Hasil Penilaian Kokurikuler</h5>
                <small class="text-warning">Rekap hasil penilaian profil lulusan peserta didik</small>
            </div>
        </div>
        <div class="card-body">
            <div class="mb-3 d-flex justify-content-between align-items-start">
                <div>
                    <h6 class="mb-0">Hasil Penilaian Kokurikuler Profil lulusan Peserta Didik</h6>
                    <div class="small text-danger">Tahun Pelajaran: <strong>{{ $tahunPel }}</strong> &nbsp;|&nbsp; Semester: <strong>{{ $semester }}</strong></div>
                </div>
                <div>
                    <a href="@if(request()->is('guru/*')){{ url('guru/penilaian/kokurikuler') }}@else{{ url('admin/penilaian/kokurikuler') }}@endif" class="btn btn-secondary btn-sm">Kembali</a>
                </div>
            </div>
            {{-- Filter kelas --}}
            <form method="GET" action="@if(request()->is('guru/*')){{ url('guru/penilaian/kokurikuler/hasil') }}@else{{ url('admin/penilaian/kokurikuler/hasil') }}@endif" class="row g-2 align-items-center mb-3">
                <div class="col-auto">
                    <label class="visually-hidden" for="filterKelas">Kelas</label>
                    <select name="kelas" id="filterKelas" class="form-select form-select-sm">
                        <option value="">-- Pilih Kelas --</option>
                        @if(isset($kelasList))
                            @foreach($kelasList as $k)
                                <option value="{{ $k->id }}" @if(isset($selectedKelas) && $selectedKelas == $k->id) selected @endif>{{ data_get($k, 'nama_kelas') ?? data_get($k, 'nama') ?? $k->id }}</option>
                            @endforeach
                        @endif
                    </select>
                </div>
                <div class="col-auto">
                    <button class="btn btn-primary btn-sm" type="submit">Cari</button>
                    <a href="{{ url('admin/penilaian/kokurikuler/hasil') }}" class="btn btn-outline-secondary btn-sm ms-1">Reset</a>
                </div>
            </form>
            {{-- Konten rekap hasil --}}
            <div class="table-responsive mt-3">
                <table class="table table-striped table-bordered">
                    <colgroup>
                        <col style="width:30%;"> <!-- Nama Peserta Didik -->
                        <col style="width:10%;"> <!-- Kelas (sesuaikan) -->
                        <col> <!-- Kokurikuler (flex) -->
                    </colgroup>
                    <thead class="table-light">
                        <tr>
                            <th>Nama Peserta Didik</th>
                            <th>Kelas</th>
                            <th>Kokurikuler</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if(isset($rekap) && $rekap->count())
                            @foreach($rekap as $row)
                                <tr>
                                    <td>{{ data_get($row, 'nama') ?? '-' }}</td>
                                    <td>{{ data_get($row, 'kelas') ?? '-' }}</td>
                                            <td><p class="mb-0">{{ data_get($row, 'kokurikuler') ?? '-' }}</p></td>
                                </tr>
                            @endforeach
                        @else
                            <tr>
                                <td colspan="3" class="text-center text-muted">Belum ada data rekap penilaian.</td>
                            </tr>
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
    </section>
@endsection
