@extends('layouts.app')

@section('title', 'Data Murid Naik Jenjang')

@section('content')
<div class="container-fluid">
    <!-- Page Header -->
    <div class="mb-4">
        <h2 class="mb-1">
            <i class="bi bi-arrow-up-circle-fill text-success"></i>
            Data Murid Naik Jenjang
        </h2>
        <p class="text-muted mb-0">Rekapitulasi data murid naik jenjang dari seluruh sekolah</p>
    </div>

    <!-- Stats Cards -->
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <p class="text-muted mb-1">Total Murid Naik Jenjang</p>
                            <h3 class="mb-0">{{ $students->total() }}</h3>
                        </div>
                        <div class="bg-success bg-opacity-10 p-3 rounded">
                            <i class="bi bi-arrow-up-circle-fill fs-3 text-success"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Filter Card -->
    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <form method="GET" action="{{ route('admin-dinas.naik-jenjang') }}" class="row g-3">
                <div class="col-md-3">
                    <label class="form-label">Cari</label>
                    <input type="text" name="search" class="form-control" placeholder="Nama, NIK, NISN, NIS" value="{{ request('search') }}">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Sekolah</label>
                    <select name="school_id" class="form-select">
                        <option value="">Semua Sekolah</option>
                        @foreach($schools as $school)
                            <option value="{{ $school->id }}" {{ request('school_id') == $school->id ? 'selected' : '' }}>
                                {{ $school->name }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">Jenjang</label>
                    <select name="jenjang" class="form-select">
                        <option value="">Semua</option>
                        <option value="SDLB" {{ request('jenjang') == 'SDLB' ? 'selected' : '' }}>SDLB</option>
                        <option value="SMPLB" {{ request('jenjang') == 'SMPLB' ? 'selected' : '' }}>SMPLB</option>
                        <option value="SMALB" {{ request('jenjang') == 'SMALB' ? 'selected' : '' }}>SMALB</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">Ketunaan</label>
                    <select name="disability_type_id" class="form-select">
                        <option value="">Semua</option>
                        @foreach($disabilityTypes as $type)
                            <option value="{{ $type->id }}" {{ request('disability_type_id') == $type->id ? 'selected' : '' }}>
                                {{ $type->name }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="bi bi-search me-1"></i> Filter
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Students Table -->
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white py-3">
            <div class="d-flex justify-content-between align-items-center">
                <h5 class="mb-0">
                    <i class="bi bi-list-ul text-success me-2"></i>
                    Daftar Murid Naik Jenjang
                </h5>
                <span class="badge bg-success">{{ $students->total() }} Siswa</span>
            </div>
        </div>
        <div class="card-body p-0">
            @if($students->count() > 0)
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th width="5%">No</th>
                            <th width="18%">Nama Siswa</th>
                            <th width="18%">Sekolah</th>
                            <th width="10%">NISN/NIS</th>
                            <th width="12%">Ketunaan</th>
                            <th width="10%">Jenjang</th>
                            <th width="8%">Kelas</th>
                            <th width="8%">JK</th>
                            <th width="6%">Ijazah</th>
                            <th width="10%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($students as $index => $student)
                        <tr>
                            <td>{{ $students->firstItem() + $index }}</td>
                            <td>
                                <div class="fw-bold">{{ $student->nama }}</div>
                                <small class="text-muted">NIK: {{ $student->nik }}</small>
                            </td>
                            <td>
                                <div class="fw-bold">{{ $student->school->name }}</div>
                                <small class="text-muted">{{ $student->school->npsn }}</small>
                            </td>
                            <td>
                                <small>{{ $student->nisn }}</small><br>
                                <small class="text-muted">{{ $student->nis }}</small>
                            </td>
                            <td>
                                @if($student->disabilityType)
                                    <span class="badge bg-secondary">{{ $student->disabilityType->name }}</span>
                                @else
                                    <span class="text-muted">-</span>
                                @endif
                            </td>
                            <td>
                                <span class="badge bg-success">{{ $student->jenjang }}</span>
                            </td>
                            <td>
                                <span class="badge bg-info">{{ $student->kelas }}</span>
                            </td>
                            <td>{{ $student->jenis_kelamin }}</td>
                            <td>
                                @if($student->ijazah_path)
                                    <a href="{{ Storage::url($student->ijazah_path) }}" target="_blank" class="btn btn-sm btn-outline-primary">
                                        <i class="bi bi-file-earmark-pdf"></i>
                                    </a>
                                @else
                                    -
                                @endif
                            </td>
                            <td class="text-center">
                                <a href="{{ route('admin-dinas.murid.detail', $student->id) }}" 
                                   class="btn btn-sm btn-info" title="Detail">
                                    <i class="bi bi-eye"></i>
                                </a>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            
            <!-- Pagination -->
            <div class="card-footer bg-white">
                <div class="d-flex justify-content-between align-items-center">
                    <div class="text-muted small">
                        Menampilkan {{ $students->firstItem() }} - {{ $students->lastItem() }} dari {{ $students->total() }} siswa
                    </div>
                    <div>
                        {{ $students->links() }}
                    </div>
                </div>
            </div>
            @else
            <div class="text-center py-5">
                <i class="bi bi-inbox display-1 text-muted"></i>
                <p class="text-muted mt-3">
                    @if(request()->hasAny(['search', 'school_id', 'jenjang', 'disability_type_id']))
                        Tidak ada data yang sesuai dengan filter.
                    @else
                        Belum ada data murid naik jenjang.
                    @endif
                </p>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection
