<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Daftar Pelanggaran') }}
        </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-lg rounded-lg overflow-hidden">
                <div class="p-6">

                    <form action="{{ route('pelanggarans.index') }}" method="GET" class="mb-4">
                        <input type="text" name="search" placeholder="Cari nama santri..."
                            value="{{ request('search') }}" class="border px-3 py-2 rounded-lg">
                        <button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded-lg">Cari</button>
                    </form>

                    {{-- Judul dan tombol tambah --}}
                    <div class="flex items-center justify-between mb-6">
                        <h2 class="text-2xl font-bold text-green-700">Daftar Pelanggaran Santri</h2>
                        <!-- <a href="{{ route('pelanggarans.create') }}"
                            class="bg-green-600 text-white px-4 py-2 rounded-lg shadow hover:bg-green-700 transition">
                            + Tambah Pelanggaran
                        </a> -->
                    </div>

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

                    {{-- Tabel daftar pelanggaran --}}
                    <div class="overflow-x-auto">
                        <table class="min-w-full border border-gray-200 rounded-lg">
                            <thead class="bg-green-100">
                                <tr>
                                    <th class="px-4 py-2 border">No</th>
                                    <th class="px-4 py-2 border">Santri</th>
                                    <th class="px-4 py-2 border">Kelas</th>
                                    <th class="px-4 py-2 border">Jenis Pelanggaran</th>
                                    <th class="px-4 py-2 border">Keterangan</th>
                                    <th class="px-4 py-2 border">Status Hukuman</th>
                                    <th class="px-4 py-2 border text-center">Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($pelanggarans as $i => $p)
                                    <tr class="hover:bg-gray-50">
                                        <td class="px-4 py-2 border text-center">{{ $i + 1 }}</td>
                                        <td class="px-4 py-2 border">{{ $p->santri->nama }}</td>
                                        <td class="px-4 py-2 border">{{ $p->kelas->nama_kelas }}</td>
                                        <td class="px-4 py-2 border">{{ $p->jenis_pelanggaran }}</td>
                                        <td class="px-4 py-2 border">{{ $p->keterangan_hukuman }}</td>
                                        <td class="px-4 py-2 border text-center">
                                            @if($p->hukuman_selesai === 'selesai')
                                                <span
                                                    class="px-2 py-1 text-xs rounded-full bg-green-200 text-green-800">Selesai</span>
                                            @else
                                                <span
                                                    class="px-2 py-1 text-xs rounded-full bg-yellow-200 text-yellow-800">Belum</span>
                                            @endif
                                        </td>
                                        <td class="px-4 py-2 border text-center">
                                            <a href="{{ route('pelanggarans.edit', $p->id) }}"
                                                class="inline-block px-3 py-1 bg-yellow-400 text-white rounded hover:bg-yellow-500 transition">
                                                Edit
                                            </a>
                                            <form action="{{ route('pelanggarans.destroy', $p->id) }}" method="POST"
                                                class="inline-block" onsubmit="return confirm('Hapus data ini?')">
                                                @csrf @method('DELETE')
                                                <button type="submit"
                                                    class="px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600 transition">
                                                    Hapus
                                                </button>
                                            </form>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="7" class="px-4 py-3 border text-center text-gray-500">
                                            Tidak ada data pelanggaran
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>