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

    <div class="py-12">
        <div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-xl sm:rounded-2xl">
                <div class="p-8">
                    <!-- Header Section -->
                    <div class="mb-8">
                        <h2 class="text-3xl font-bold text-gray-800 mb-2">Edit Jadwal</h2>
                        <p class="text-gray-600">Ubah informasi jadwal pelajaran</p>
                    </div>

                    <form action="{{ route('jadwals.update', $jadwal) }}" method="POST">
                        @csrf
                        @method('PUT')

                        <div class="bg-gray-50 rounded-xl p-6 mb-8">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">Informasi Jadwal</h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Kelas</label>
                                    <select name="kelas_id" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500" required>
                                        <option value="">Pilih Kelas</option>
                                        @foreach($kelas as $k)
                                            <option value="{{ $k->id }}" {{ old('kelas_id', $jadwal->kelas_id) == $k->id ? 'selected' : '' }}>
                                                {{ $k->nama_kelas }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @error('kelas_id')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Mata Pelajaran</label>
                                    <select name="mata_pelajaran_id" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500" required>
                                        <option value="">Pilih Mata Pelajaran</option>
                                        @foreach($mapels as $m)
                                            <option value="{{ $m->id }}" {{ old('mapel_id', $jadwal->mapel_id ?? $jadwal->mata_pelajaran_id) == $m->id ? 'selected' : '' }}>
                                                {{ $m->nama_mapel }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @error('mapel_id')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Wali Kelas</label>
                                    <select name="guru_id" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500">
                                        <option value="">Pilih Wali Kelas</option>
                                        @foreach($gurus as $guru)
                                            <option value="{{ $guru->id }}" {{ old('guru_id', $jadwal->guru_id) == $guru->id ? 'selected' : '' }}>
                                                {{ $guru->nama }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @error('guru_id')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Hari</label>
                                    <select name="hari" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500" required>
                                        @foreach(['Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu'] as $hari)
                                            <option value="{{ $hari }}" {{ old('hari', $jadwal->hari) == $hari ? 'selected' : '' }}>{{ $hari }}</option>
                                        @endforeach
                                    </select>
                                    @error('hari')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Jam Mulai</label>
                                    <input type="time" name="jam_mulai" class="w-full px-4 py-3 border border-gray-300 rounded-lg" value="{{ old('jam_mulai', $jadwal->jam_mulai) }}" required>
                                    @error('jam_mulai')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Jam Selesai</label>
                                    <input type="time" name="jam_selesai" class="w-full px-4 py-3 border border-gray-300 rounded-lg" value="{{ old('jam_selesai', $jadwal->jam_selesai) }}" required>
                                    @error('jam_selesai')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                                </div>
                            </div>

                            <div class="mt-6">
                                <label class="block text-sm font-medium text-gray-700 mb-2">Ruangan</label>
                                <input type="text" name="ruangan" class="w-full px-4 py-3 border border-gray-300 rounded-lg" value="{{ old('ruangan', $jadwal->ruangan) }}" required>
                                @error('ruangan')<div class="text-red-600 text-sm mt-1">{{ $message }}</div>@enderror
                            </div>
                        </div>

                        <div class="flex justify-end space-x-4">
                            <a href="{{ route('jadwals.index') }}" class="px-6 py-3 text-sm text-gray-700 bg-gray-200 rounded-lg hover:bg-gray-300">Kembali</a>
                            <button type="submit" class="px-6 py-3 text-sm text-white bg-teal-600 rounded-lg hover:bg-teal-700">Update Jadwal</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
