<x-app-layout>
    @section('title', 'Kategori Obat')

    <div class="space-y-6">
        <!-- Header -->
        <div class="flex items-center justify-between">
            <h1 class="text-2xl font-bold text-[#2F347A]">Kategori Obat</h1>
            <x-btn type="primary" href="{{ route('kategori.create') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
                </svg>
                Tambah Kategori
            </x-btn>
        </div>

        @if(session('success'))
            <div class="bg-[#C9F7E3] border border-[#1F9254] text-[#1F9254] px-4 py-3 rounded-lg">
                {{ session('success') }}
            </div>
        @endif

        <x-card class="overflow-hidden">
            <div class="px-6 py-4 table-header-custom">
                <h2 class="text-lg font-semibold">Daftar Kategori</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead class="bg-[#F4F6FF] border-b border-[#E5E7F2]">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-[#7A7FAE] uppercase tracking-wider">No</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-[#7A7FAE] uppercase tracking-wider">Nama Kategori</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-[#7A7FAE] uppercase tracking-wider">Keterangan</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-[#7A7FAE] uppercase tracking-wider">Aksi</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-[#E5E7F2]">
                        @forelse($kategoris as $index => $kategori)
                            <tr class="hover:bg-[#F4F6FF]">
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-[#7A7FAE]">{{ $kategoris->firstItem() + $index }}</td>
                                <td class="px-6 py-4 whitespace-nowrap font-medium text-[#2F347A]">{{ $kategori->nama }}</td>
                                <td class="px-6 py-4 text-sm text-[#7A7FAE]">{{ $kategori->keterangan ?? '-' }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm">
                                    <div class="flex gap-2">
                                        <a href="{{ route('kategori.edit', $kategori) }}" class="text-[#4A538F] hover:text-[#2F347A]">Edit</a>
                                        <form method="POST" action="{{ route('kategori.destroy', $kategori) }}" 
                                              onsubmit="return confirm('Yakin ingin menghapus?')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="text-[#C0392B] hover:text-[#a93226]">Hapus</button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="4" class="px-6 py-12 text-center text-[#7A7FAE]">Belum ada data kategori</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="px-6 py-4 border-t border-[#E5E7F2]">
                {{ $kategoris->links() }}
            </div>
        </x-card>
    </div>
</x-app-layout>
