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

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <a href="{{ route('gurus.create') }}" class="btn-primary mb-4 inline-block">Tambah Guru</a>
                    @if(session('success'))
                        <div class="alert-success mb-4">{{ session('success') }}</div>
                    @endif

                    <form action="{{ route('gurus.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>

                    <div class="overflow-x-auto">
                        <table class="table-auto w-full text-sm">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-4 py-2 text-left">No</th>
                                    <th class="px-4 py-2 text-left">Foto</th>
                                    <th class="px-4 py-2 text-left">Nama</th>
                                    <th class="px-4 py-2 text-left">CODE GURU</th>
                                    <th class="px-4 py-2 text-left">Alamat</th>
                                    <th class="px-4 py-2 text-left">Tanggal Lahir</th>
                                    <th class="px-4 py-2 text-left">Jenis Kelamin</th>
                                    <th class="px-4 py-2 text-left">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($gurus as $i => $guru)
                                    <tr class="border-b">
                                        <td class="px-4 py-2">{{ $i + 1 }}</td>
                                        <td class="px-4 py-2">
                                            @if($guru->foto)
                                                <img src="{{ asset('storage/foto_guru/' . $guru->foto) }}" alt="Foto"
                                                    class="w-16 h-16 rounded-full object-cover">
                                            @else
                                                <span class="text-gray-400 italic">Tidak ada</span>
                                            @endif
                                        </td>
                                        <td class="px-4 py-2">{{ $guru->nama }}</td>
                                        <td class="px-4 py-2">{{ $guru->code_guru }}</td>
                                        <td class="px-4 py-2">{{ $guru->alamat }}</td>
                                        <td class="px-4 py-2">
                                            {{ \Carbon\Carbon::parse($guru->tanggal_lahir)->format('d-m-Y') }}</td>
                                        <td class="px-4 py-2">{{ $guru->jenis_kelamin == 'L' ? 'Laki-laki' : 'Perempuan' }}
                                        </td>
                                        <td class="px-4 py-2 space-x-1">
                                            <!-- <a href="{{ route('gurus.edit', $guru) }}" class="btn-accent btn-sm">Edit</a> -->
                                            <form action="{{ route('gurus.destroy', $guru) }}" method="POST"
                                                class="inline-block" onsubmit="return confirm('Yakin hapus?')">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit"
                                                    class="bg-red-600 hover:bg-red-700 text-white px-3 py-1 rounded text-sm">Hapus</button>
                                            </form>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>

                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>