<x-app-layout>
    <div class="py-12 bg-gray-50 min-h-screen">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
            
            <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between bg-white p-6 rounded-2xl border border-gray-100 shadow-sm gap-4">
                <div>
                    <h2 class="text-2xl font-black text-gray-800 tracking-tight">Kelola Kategori Produk</h2>
                    <p class="text-sm text-gray-400 font-medium mt-0.5">Klasifikasi data produk untuk mempermudah alur manajemen produksi Tempe Zhi.</p>
                </div>
                <div>
                    <a href="{{ route('admin.kategori-produk.create') }}"  class="inline-flex items-center gap-2 bg-green-700 hover:bg-green-800 text-white px-5 py-2.5 rounded-xl font-bold text-xs shadow-md transition-all active:scale-95 whitespace-nowrap">
                        Tambah Kategori
                    </a>
                </div>
            </div>

            <div class="bg-white overflow-hidden shadow-sm rounded-2xl border border-gray-100">
                <div class="overflow-x-auto p-4">
                    <table class="w-full text-left border-separate border-spacing-y-2">
                        <thead>
                            <tr class="text-gray-400 text-xs uppercase tracking-wider font-bold">
                                <th class="px-6 py-4">Kode</th>
                                <th class="px-6 py-4">Nama Kategori</th>
                                <th class="px-6 py-4 text-center">Status</th>
                                <th class="px-6 py-4 text-right">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($categories as $category)
                            <tr class="group hover:bg-gray-50 transition-all border-y border-gray-100">
                                <td class="px-6 py-4 rounded-l-xl font-bold text-green-700 text-sm">
                                    #{{ $category->kode_kategori }}
                                </td>
                                <td class="px-6 py-4 font-bold text-gray-800 text-sm">
                                    {{ $category->nama_kategori }}
                                </td>
                                <td class="px-6 py-4 text-center">
                                    <span class="inline-flex items-center px-3 py-1 rounded-lg text-xs font-bold border {{ $category->status == 'aktif' ? 'bg-green-50 text-green-700 border-green-200' : 'bg-red-50 text-red-600 border-red-100' }}">
                                        {{ $category->status == 'aktif' ? 'Aktif' : 'Non-Aktif' }}
                                    </span>
                                </td>
                                <td class="px-6 py-4 text-right rounded-r-xl">
                                    <div class="flex justify-end gap-2">
                                        <a href="{{ route('admin.kategori-produk.edit', $category->id) }}" 
                                           class="inline-flex items-center p-2 text-blue-600 hover:bg-blue-50 border border-transparent hover:border-blue-100 rounded-xl transition-all">
                                            <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
                                            </svg>
                                        </a>

                                        <button type="button" 
                                                onclick="openDeleteModal('{{ $category->id }}', '{{ $category->nama_kategori }}')" 
                                                class="inline-flex items-center p-2 text-red-600 hover:bg-red-50 border border-transparent hover:border-red-100 rounded-xl transition-all">
                                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                                </svg>
                                        </button>
                                        
                                        <form id="form-delete-{{ $category->id }}" action="{{ route('admin.kategori-produk.destroy', $category->id) }}" method="POST" class="hidden">
                                            @csrf 
                                            @method('DELETE')
                                        </form>
                                    </div>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <x-delete-confirmation />
</x-app-layout>