@extends('guru.layouts.app')

@section('title', 'Daftar Siswa')

@section('content')

<style>
    .page-title {
        font-size: 30px;
        font-weight: 800;
        margin-bottom: 10px;
        margin-top: -20px;
    }

    .custom-card {
        background: white;
        border-radius: 20px;
        border: 2px solid #e5e5e5;
        padding: 25px;
    }

    .table-header {
        background: #bae6fd;
    }

    .search-box {
        background: #bae6fd;
        border-radius: 30px;
        padding: 6px 15px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .search-box input {
        border: none;
        outline: none;
        background: transparent;
        width: 150px;
    }

    .per-page-select, .filter-select {
        border-radius: 10px;
        padding: 5px;
        border: 1px solid #ccc;
    }

    .badge-info {
        background: #e0f2fe;
        color: #0369a1;
        padding: 5px 12px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
    }
</style>

<h3 class="page-title">DAFTAR SISWA</h3>

<div class="custom-card">

    <div class="d-flex justify-content-between align-items-center mb-3">

        <form method="GET">
            <div class="search-box">
                <input type="text" name="search" placeholder="Cari" value="{{ request('search') }}">
                <button style="border:none;background:none">
                    <img src="{{ asset('images/icon/main/search.png') }}" width="18" height="18" alt="Cari siswa">
                </button>
            </div>
        </form>

    </div>

    <form method="GET" class="mb-2">
        <span>Tampilkan</span>

        <select name="perPage" onchange="this.form.submit()" class="per-page-select">
            <option value="10" {{ request('perPage') == 10 ? 'selected' : '' }}>10</option>
            <option value="25" {{ request('perPage') == 25 ? 'selected' : '' }}>25</option>
            <option value="50" {{ request('perPage') == 50 ? 'selected' : '' }}>50</option>
        </select>

        <span>data</span>

        <span class="ms-3">Filter Kelas</span>

        <select name="filter_kelas" onchange="this.form.submit()" class="filter-select">
            <option value="">Semua Kelas</option>
            @foreach($kelass as $kelas)
                <option value="{{ $kelas->id_kelas }}"
                    {{ request('filter_kelas') == $kelas->id_kelas ? 'selected' : '' }}>
                    {{ $kelas->tingkat }} - {{ $kelas->nama_kelas }}
                </option>
            @endforeach
        </select>

        <input type="hidden" name="search" value="{{ request('search') }}">
    </form>

    <table class="table text-center align-middle">
        <thead class="table-header">
            <tr>
                <th>No</th>
                <th>NISN</th>
                <th>Nama</th>
                <th>Tempat Lahir</th>
                <th>Tanggal Lahir</th>
                <th>Kelas</th>
            </tr>
        </thead>

        <tbody>
            @forelse($siswas as $index => $siswa)
            <tr>
                <td>{{ $siswas->firstItem() + $index }}</td>
                <td>{{ $siswa->nisn }}</td>
                <td>{{ $siswa->nama }}</td>
                <td>{{ $siswa->tempat_lahir }}</td>
                <td>{{ \Carbon\Carbon::parse($siswa->tanggal_lahir)->format('d M Y') }}</td>
                <td>{{ $siswa->kelas->tingkat }} - {{ $siswa->kelas->nama_kelas }}</td>
            </tr>

            @empty
            <tr>
                <td colspan="6">Belum ada data siswa</td>
            </tr>
            @endforelse
        </tbody>
    </table>

    <div class="d-flex justify-content-end">
        {{ $siswas->links() }}
    </div>

</div>

@endsection