<?php $__env->startSection('content'); ?>
    <div class="mb-4 flex items-center justify-between gap-3">
        <div>
            <div class="text-xl font-bold">Jadwal Pelajaran</div>
            <div class="text-sm text-slate-500 dark:text-slate-400">
                Kelola jadwal per kelas.
            </div>
        </div>
        <div class="flex items-center gap-2">
            <a
                href="<?php echo e(route('admin.jadwal.export.pdf')); ?>"
                class="rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm font-semibold hover:bg-slate-50 dark:border-slate-800 dark:bg-slate-950 dark:hover:bg-slate-900"
            >
                Export PDF
            </a>
            <a
                href="<?php echo e(route('admin.jadwal.create')); ?>"
                class="rounded-lg bg-blue-600 px-3 py-2 text-sm font-semibold text-white hover:bg-blue-700"
            >
                Tambah
            </a>
        </div>
    </div>
    <div class="mb-4">
        <form method="GET" action="<?php echo e(route('admin.jadwal.index')); ?>">
            <div class="grid grid-cols-1 gap-3 md:grid-cols-4">
                <!-- SEARCH -->
                <input
    type="text"
    id="liveSearch"
    name="search"
    value="<?php echo e(request('search')); ?>"
    placeholder="Cari hari, mapel, guru..."
    autocomplete="off"
    spellcheck="false"
    class="rounded-lg border border-slate-300 px-4 py-2 text-sm focus:border-blue-500 focus:outline-none dark:border-slate-700 dark:bg-slate-900"
/>

                <!-- FILTER KELAS -->
                <select
    id="kelasFilter"
    name="kelas_id"
                    class="rounded-lg border border-slate-300 px-4 py-2 text-sm dark:border-slate-700 dark:bg-slate-900"
                >
                    <option value="">Semua Kelas</option>

                    <?php $__currentLoopData = $kelasList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kelas): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option
                            value="<?php echo e($kelas->kelas_id); ?>"
                            <?php if((string)$kelasId === (string)$kelas->kelas_id): echo 'selected'; endif; ?>
                        >
                            <?php echo e($kelas->nama_kelas); ?>

                        </option>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>

                <!-- FILTER JURUSAN -->
                <select
    id="jurusanFilter"
    name="jurusan"
                    class="rounded-lg border border-slate-300 px-4 py-2 text-sm dark:border-slate-700 dark:bg-slate-900"
                >
                    <option value="">Semua Jurusan</option>

                    <?php $__currentLoopData = $jurusans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $j): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($j); ?>" <?php if($jurusan === $j): echo 'selected'; endif; ?>>
                            <?php echo e($j); ?>

                        </option>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>

                <!-- BUTTON -->
                <div class="flex gap-2">
                    <button
                        type="submit"
                        class="flex-1 rounded-lg bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700"
                    >
                        Filter
                    </button>

                    <a
                        href="<?php echo e(route('admin.jadwal.index')); ?>"
                        class="rounded-lg border border-slate-300 px-4 py-2 text-sm hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800"
                    >
                        Reset
                    </a>
                </div>
            </div>
        </form>
    </div>
    <div
        class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-950"
    >
        <table class="w-full text-left text-sm">
            <thead
                class="bg-slate-50 text-slate-600 dark:bg-slate-900/40 dark:text-slate-300"
            >
                <tr>
                    <th class="px-4 py-3">Hari</th>
                    <th class="px-4 py-3">Jam</th>
                    <th class="px-4 py-3">Kelas</th>
                    <th class="px-4 py-3">Mapel</th>
                    <th class="px-4 py-3">Guru</th>
                    <th class="px-4 py-3 text-right">Aksi</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-200 dark:divide-slate-800">
                <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td class="px-4 py-3"><?php echo e($item->hari); ?></td>
                        <td class="px-4 py-3 font-mono">
                            <?php echo e($item->jam_mulai); ?> - <?php echo e($item->jam_selesai); ?>

                        </td>
                        <td class="px-4 py-3">
                            <?php echo e($item->kelas?->nama_kelas); ?>

                        </td>
                        <td class="px-4 py-3">
                            <?php echo e($item->mapel?->nama_mapel); ?>

                        </td>
                        <td class="px-4 py-3"><?php echo e($item->guru?->nama_guru); ?></td>
                        <td class="px-4 py-3">
                            <div class="flex justify-end gap-2">
                                <a
                                    href="<?php echo e(route('admin.jadwal.edit', $item->jadwal_id)); ?>"
                                    class="rounded-lg px-3 py-2 text-xs font-semibold hover:bg-slate-100 dark:hover:bg-slate-900"
                                    >Edit</a
                                >
                                <form
                                    method="POST"
                                    action="<?php echo e(route('admin.jadwal.destroy', $item->jadwal_id)); ?>"
                                    onsubmit="
                                        return confirm('Hapus data ini?');
                                    "
                                >
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('DELETE'); ?>
                                    <button
                                        class="rounded-lg bg-red-600 px-3 py-2 text-xs font-semibold text-white hover:bg-red-700"
                                    >
                                        Hapus
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
    <div class="mt-4"><?php echo e($items->links()); ?></div>
<?php $__env->stopSection(); ?>
<script>
document.addEventListener("DOMContentLoaded", function(){

    const input = document.getElementById("liveSearch");
    const kelas = document.getElementById("kelasFilter");
    const jurusan = document.getElementById("jurusanFilter");

    if(input){

        // otomatis fokus kembali
        input.focus();

        // pindahkan cursor ke akhir tulisan
        let val = input.value;
        input.value = '';
        input.value = val;

        let timer;

        input.addEventListener("input", function(){

            clearTimeout(timer);

            timer = setTimeout(() => {
                input.form.submit();
            }, 100);

        });

    }

    if(kelas){
        kelas.addEventListener("change", function(){
            this.form.submit();
        });
    }

    if(jurusan){
        jurusan.addEventListener("change", function(){
            this.form.submit();
        });
    }

});
</script>
<?php echo $__env->make('layouts.app', ['title' => 'Admin - Jadwal'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\sistem-absensi-smkn-2-rupat\resources\views/admin/jadwal/index.blade.php ENDPATH**/ ?>