<x-app-layout>
    <x-slot name="header">
        <h2 class="font-black text-xl text-green-900 leading-tight flex items-center gap-2">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-green-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
            </svg>
            {{ __('Legalitas & Sertifikat') }}
        </h2>
    </x-slot>

    <div class="py-12 bg-gray-50/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-8 rounded-3xl border border-gray-100 shadow-sm gap-4">
                <div>
                    <h2 class="text-2xl font-black text-gray-900 tracking-tight">Daftar Sertifikat</h2>
                    <p class="text-sm text-gray-500 font-medium mt-1">Kelola dokumen legalitas dan lisensi usaha.</p>
                </div>
                <a href="{{ route('admin.sertifikat.create') }}" class="inline-flex items-center gap-2 bg-green-700 hover:bg-green-800 text-white px-6 py-3 rounded-2xl font-bold text-xs shadow-lg shadow-green-700/20 transition-all active:scale-95">
                    Tambah Sertifikat
                </a>
            </div>

            <div class="bg-white rounded-3xl shadow-sm border border-gray-100 overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="w-full text-left border-collapse">
                        <thead>
                            <tr class="text-gray-400 text-[10px] uppercase tracking-[0.2em] font-black bg-gray-50/50">
                                <th class="px-8 py-4">Dokumen</th>
                                <th class="px-6 py-4">Nama Sertifikat</th>
                                <th class="px-6 py-4 text-center">Nomor Registrasi</th>
                                <th class="px-8 py-4 text-right">Aksi</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-100">
                            @forelse($sertifikats as $s)
                            <tr class="group hover:bg-green-50/30 transition-colors">
                                <td class="px-6 py-5 rounded-l-2xl">
                                    <div class="h-16 w-16 rounded-xl overflow-hidden bg-gray-100 border border-green-100 shadow-sm">
                                        <img src="{{ asset('storage/' . $s->gambar) }}" class="h-full w-full object-contain p-1">
                                    </div>
                                </td>
                                <td class="px-6 py-5">
                                    <div class="font-bold text-gray-900 text-sm">{{ $s->nama_sertifikat }}</div>
                                    <div class="text-[10px] text-gray-400 uppercase font-black tracking-widest mt-0.5">Dokumen Resmi</div>
                                </td>
                                <td class="px-6 py-5 text-center">
                                    <code class="px-3 py-1 bg-gray-100/50 text-gray-700 rounded-lg text-[11px] font-bold border border-gray-200">
                                        {{ $s->nomor_sertifikat }}
                                    </code>
                                </td>
                                <td class="px-8 py-5 text-right">
                                    <div class="flex justify-end gap-2">
                                        {{-- Tombol Edit --}}
                                        <a href="{{ route('admin.sertifikat.edit', $s->id) }}" class="p-2.5 text-blue-600 hover:bg-blue-50 rounded-xl transition border border-transparent hover:border-blue-100">
                                            <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
                                                <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
                                            </svg>
                                        </a>

                                        {{-- 1. Form Delete Hidden (DITAMBAHKAN) --}}
                                        <form id="form-delete-{{ $s->id }}" action="{{ route('admin.sertifikat.destroy', $s->id) }}" method="POST" class="hidden">
                                            @csrf
                                            @method('DELETE')
                                        </form>

                                        {{-- 2. Tombol Trigger Modal Hapus (DIPERBAIKI) --}}
                                        <button type="button" 
                                                onclick="openDeleteModal('{{ $s->id }}', '{{ addslashes($s->nama_sertifikat) }}')" 
                                                class="p-2.5 text-red-500 hover:bg-red-50 rounded-xl transition border border-transparent hover:border-red-100">
                                            <svg xmlns="http://www.w3.org/2000/xl" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
                                                <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                                            </svg>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="4" class="py-20 text-center text-gray-400 font-medium">Belum ada data sertifikat.</td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <x-delete-confirmation />
</x-app-layout>