<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Daftar Jadwal') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white shadow overflow-hidden sm:rounded-lg p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-2xl font-bold text-gray-800">Jadwal Kelas</h2>
                    <a href="{{ route('jadwals.create') }}" class="px-4 py-2 bg-teal-600 text-white rounded hover:bg-teal-700">Tambah Jadwal</a>
                </div>

                @if(session('success'))
                    <div class="bg-green-100 text-green-800 p-3 rounded mb-4">
                        {{ session('success') }}
                    </div>
                @endif

                <div class="overflow-x-auto">
                    <table class="min-w-full bg-white border border-gray-200 rounded-lg">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-4 py-2 border">No</th>
                                <th class="px-4 py-2 border">Kelas</th>
                                <th class="px-4 py-2 border">Hari</th>
                                <th class="px-4 py-2 border">Jam</th>
                                <th class="px-4 py-2 border">Mapel</th>
                                <th class="px-4 py-2 border">Ruangan</th>
                                <th class="px-4 py-2 border">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($jadwals as $i => $jadwal)
                                <tr class="text-center">
                                    <td class="px-4 py-2 border">{{ $i + 1 }}</td>
                                    <td class="px-4 py-2 border">{{ $jadwal->kelas->nama_kelas ?? '-' }}</td>
                                    <td class="px-4 py-2 border">{{ $jadwal->hari }}</td>
                                    <td class="px-4 py-2 border">{{ $jadwal->jam_mulai }} - {{ $jadwal->jam_selesai }}</td>
                                    <td class="px-4 py-2 border">{{ $jadwal->mataPelajaran->nama_mapel ?? '-' }}</td>
                                    <td class="px-4 py-2 border">{{ $jadwal->ruangan ?? '-' }}</td>
                                    <td class="px-4 py-2 border space-x-2">
                                        <a href="{{ route('jadwals.edit', $jadwal) }}" class="px-3 py-1 bg-yellow-400 text-white rounded">Edit</a>
                                        <form action="{{ route('jadwals.destroy', $jadwal) }}" method="POST" class="inline-block" onsubmit="return confirm('Yakin ingin hapus?')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="px-3 py-1 bg-red-600 text-white rounded">Delete</button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
