<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Daftar catatan kesehatan') }}
        </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">

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

                    <h1 class="mb-4 text-xl font-bold text-primary">Catatan Kesehatan</h1>
                    <!-- <a href="{{ route('catatan_kesehatans.create') }}" class="btn-primary">Tambah Catatan</a> -->
                    @if(session('success'))
                        <div class="alert-success mb-4">{{ session('success') }}</div>
                    @endif
                    <div class="overflow-x-auto">
                        <table class="table w-full border rounded-lg overflow-hidden">
                            <thead>
                                <tr class="table-header">
                                    <th class="px-3 py-2">No</th>
                                    <th class="px-3 py-2">Santri</th>
                                    <th class="px-3 py-2">Kelas</th>
                                    <th class="px-3 py-2">Keluhan</th>
                                    <th class="px-3 py-2">Diagnosis</th>
                                    <th class="px-3 py-2">Saran</th>
                                    <th class="px-3 py-2">Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($catatanKesehatans as $catatan)
                                    <tr class="table-row">
                                        <td class="px-3 py-2">
                                            {{ $loop->iteration + ($catatanKesehatans->currentPage() - 1) * $catatanKesehatans->perPage() }}
                                        </td>
                                        <td class="px-3 py-2">{{ $catatan->santri->nama ?? '-' }}</td>
                                        <td class="px-3 py-2">{{ $catatan->kelas->nama_kelas ?? '-' }}</td>
                                        <td class="px-3 py-2">{{ $catatan->keluhan }}</td>
                                        <td class="px-3 py-2">{{ $catatan->diagnosis }}</td>
                                        <td class="px-3 py-2">{{ $catatan->saran }}</td>
                                        <td class="px-3 py-2 space-x-1">
                                            <a href="{{ route('catatan_kesehatans.show', $catatan) }}"
                                                class="btn-accent btn-sm">Detail</a>
                                            <a href="{{ route('catatan_kesehatans.edit', $catatan) }}"
                                                class="btn-accent btn-sm">Edit</a>
                                            <form action="{{ route('catatan_kesehatans.destroy', $catatan) }}" method="POST"
                                                style="display:inline-block;">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="btn-primary btn-sm"
                                                    onclick="return confirm('Yakin hapus?')">Hapus</button>
                                            </form>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    {{ $catatanKesehatans->links() }}


</x-app-layout>