<x-admin-layout>
    <x-slot name="header">
        {{ __('Kategori Produk') }}
    </x-slot>

    <div class="flex justify-end mb-4">
        <a href="{{ route('admin.categories.create') }}" class="inline-flex items-center px-4 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors">
            <x-heroicon-o-plus class="-ml-1 mr-2 h-5 w-5" />
            Tambah Kategori
        </a>
    </div>

    <!-- Table Section -->
    <div class="bg-white dark:bg-slate-800 rounded-2xl shadow-sm border border-gray-100 dark:border-slate-700 overflow-hidden">
        <div class="px-6 py-5 border-b border-gray-100 dark:border-slate-700 flex flex-col sm:flex-row justify-between items-center gap-4">
            <h3 class="font-semibold text-gray-800 dark:text-gray-100">Daftar Kategori</h3>
            <div class="w-full sm:w-64">
                <div class="relative rounded-md shadow-sm">
                    <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                        <x-heroicon-o-magnifying-glass class="h-4 w-4 text-gray-400" />
                    </div>
                    <input type="text" class="focus:ring-indigo-500 focus:border-indigo-500 block w-full pl-10 text-sm border-gray-300 dark:border-slate-600 rounded-lg placeholder-gray-400 dark:bg-slate-700 dark:text-white dark:border-slate-600" placeholder="Cari kategori...">
                </div>
            </div>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full text-sm text-left whitespace-nowrap">
                <thead class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50 dark:bg-slate-700/50 border-b border-gray-100 dark:border-slate-700">
                    <tr>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider">Info Kategori</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider text-center">Produk</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider">Status</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100 dark:divide-slate-700 bg-white dark:bg-slate-800">
                    @forelse ($categories as $category)
                    <tr class="hover:bg-gray-50 dark:hover:bg-slate-700/50 dark:bg-slate-700/50 transition-colors">
                        <td class="px-6 py-4">
                            <div class="flex items-center">
                                <div class="flex-shrink-0 h-10 w-10 flex items-center justify-center rounded-lg bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-400 mr-4">
                                    <x-dynamic-component :component="'heroicon-o-' . ($category->icon ?: 'folder')" class="h-6 w-6" />
                                </div>
                                <div>
                                    <div class="font-medium text-gray-900 dark:text-white">{{ $category->name }}</div>
                                    <div class="text-xs text-gray-500 dark:text-gray-400 mt-0.5 font-mono">{{ $category->slug }}</div>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-center">
                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-slate-700 text-gray-800 dark:text-gray-100">
                                {{ $category->products_count ?? 0 }} item
                            </span>
                        </td>
                        <td class="px-6 py-4">
                            @if($category->is_active)
                                <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold bg-emerald-50 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400 border border-emerald-100 dark:border-emerald-800">
                                    <span class="w-1.5 h-1.5 rounded-full bg-emerald-50 dark:bg-emerald-900/300"></span> Aktif
                                </span>
                            @else
                                <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold bg-gray-50 dark:bg-slate-700/50 text-gray-600 dark:text-gray-300 border border-gray-200 dark:border-slate-700">
                                    <span class="w-1.5 h-1.5 rounded-full bg-gray-400"></span> Nonaktif
                                </span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{{ route('admin.categories.edit', $category) }}" class="p-2 text-gray-400 hover:text-indigo-600 dark:hover:text-indigo-400 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 dark:bg-indigo-900/30 rounded-lg transition-colors" title="Edit">
                                    <x-heroicon-o-pencil-square class="w-5 h-5" />
                                </a>
                                <form action="{{ route('admin.categories.destroy', $category) }}" method="POST" data-confirm="Apakah Anda yakin ingin menghapus kategori ini?" class="inline-block">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="p-2 text-gray-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30 dark:bg-red-900/30 rounded-lg transition-colors" title="Delete">
                                        <x-heroicon-o-trash class="w-5 h-5" />
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="4" class="px-6 py-12 text-center text-gray-500 dark:text-gray-400">
                            <div class="flex flex-col items-center justify-center">
                                <div class="w-16 h-16 rounded-full bg-gray-100 dark:bg-slate-700 flex items-center justify-center mb-4 text-gray-400">
                                    <x-heroicon-o-folder-open class="w-8 h-8" />
                                </div>
                                <h4 class="text-base font-medium text-gray-900 dark:text-white mb-1">Tidak ada kategori</h4>
                                <p class="text-sm">Mulai dengan menambahkan kategori baru untuk produk Anda.</p>
                                <a href="{{ route('admin.categories.create') }}" class="mt-4 text-indigo-600 dark:text-indigo-400 font-medium hover:text-indigo-800 text-sm">
                                    + Tambah Kategori
                                </a>
                            </div>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        
        <!-- Pagination -->
        @if($categories->hasPages())
        <div class="px-6 py-4 border-t border-gray-100 dark:border-slate-700 bg-gray-50 dark:bg-slate-700/50">
            {{ $categories->links() }}
        </div>
        @endif
    </div>
</x-admin-layout>
