<x-admin-layout>
    <x-slot name="header">
        <h2 class="font-bold text-2xl text-gray-900 dark:text-white leading-tight">Halaman Statis</h2>
    </x-slot>

    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
        <div>
            <p class="text-sm text-gray-500 dark:text-gray-400">Kelola halaman statis yang dapat diakses publik.</p>
        </div>
        <a href="{{ route('admin.pages.create') }}" class="inline-flex items-center gap-2 px-5 py-2.5 bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-bold rounded-xl shadow-sm transition-colors">
            <x-heroicon-s-plus class="w-4 h-4" />
            Buat Halaman Baru
        </a>
    </div>

    <div class="bg-white dark:bg-slate-800 rounded-2xl shadow-sm border border-gray-100 dark:border-slate-700 overflow-hidden">
        @if($pages->count() > 0)
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-100 dark:divide-slate-700">
                <thead>
                    <tr class="bg-gray-50 dark:bg-slate-700/50">
                        <th class="px-6 py-3.5 text-left text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Judul</th>
                        <th class="px-6 py-3.5 text-left text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Slug / URL</th>
                        <th class="px-6 py-3.5 text-center text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Status</th>
                        <th class="px-6 py-3.5 text-center text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Footer</th>
                        <th class="px-6 py-3.5 text-left text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Dibuat</th>
                        <th class="px-6 py-3.5 text-center text-[11px] font-black uppercase tracking-widest text-gray-500 dark:text-gray-400">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50 dark:divide-slate-700/50">
                    @foreach($pages as $page)
                    <tr class="hover:bg-gray-50/50 dark:hover:bg-slate-700/30 transition-colors">
                        <td class="px-6 py-4">
                            <div class="font-semibold text-sm text-gray-900 dark:text-white">{{ $page->title }}</div>
                            @if($page->meta_description)
                            <div class="text-xs text-gray-400 mt-0.5 truncate max-w-xs">{{ Str::limit($page->meta_description, 60) }}</div>
                            @endif
                        </td>
                        <td class="px-6 py-4">
                            <a href="{{ route('page.show', $page->slug) }}" target="_blank"
                               class="text-sm text-indigo-600 hover:text-indigo-800 font-mono flex items-center gap-1.5 hover:underline">
                                /page/{{ $page->slug }}
                                <x-heroicon-o-arrow-top-right-on-square class="w-3.5 h-3.5 flex-shrink-0" />
                            </a>
                        </td>
                        <td class="px-6 py-4 text-center">
                            @if($page->status === 'published')
                                <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-green-50 text-green-700 border border-green-200">
                                    <span class="w-1.5 h-1.5 bg-green-500 rounded-full mr-1.5"></span> Terbit
                                </span>
                            @else
                                <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-gray-100 text-gray-600 border border-gray-200">
                                    <span class="w-1.5 h-1.5 bg-gray-400 rounded-full mr-1.5"></span> Draft
                                </span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-center">
                            @if($page->show_in_footer)
                                <x-heroicon-s-check-circle class="w-5 h-5 text-indigo-500 mx-auto" />
                            @else
                                <x-heroicon-o-minus-circle class="w-5 h-5 text-gray-300 mx-auto" />
                            @endif
                        </td>
                        <td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">
                            {{ $page->created_at->format('d M Y') }}
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex items-center justify-center gap-2">
                                <a href="{{ route('admin.pages.edit', $page) }}"
                                   class="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-bold text-indigo-700 bg-indigo-50 hover:bg-indigo-100 rounded-lg transition-colors border border-indigo-100">
                                    <x-heroicon-o-pencil class="w-3.5 h-3.5" /> Edit
                                </a>
                                <form action="{{ route('admin.pages.destroy', $page) }}" method="POST"
                                      data-confirm="Hapus halaman '{{ addslashes($page->title) }}' secara permanen?">
                                    @csrf @method('DELETE')
                                    <button type="submit"
                                        class="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-bold text-red-700 bg-red-50 hover:bg-red-100 rounded-lg transition-colors border border-red-100">
                                        <x-heroicon-o-trash class="w-3.5 h-3.5" /> Hapus
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        @if($pages->hasPages())
        <div class="px-6 py-4 border-t border-gray-100 dark:border-slate-700">
            {{ $pages->links() }}
        </div>
        @endif

        @else
        <div class="flex flex-col items-center justify-center py-20 text-center">
            <x-heroicon-o-document-text class="w-14 h-14 text-gray-200 dark:text-slate-600 mb-4" />
            <h3 class="text-base font-bold text-gray-900 dark:text-white mb-1">Belum Ada Halaman</h3>
            <p class="text-sm text-gray-500 dark:text-gray-400 mb-6">Buat halaman statis seperti "Tentang Kami" atau "Syarat & Ketentuan".</p>
            <a href="{{ route('admin.pages.create') }}" class="inline-flex items-center gap-2 px-5 py-2.5 bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-bold rounded-xl transition-colors">
                <x-heroicon-s-plus class="w-4 h-4" /> Buat Halaman Pertama
            </a>
        </div>
        @endif
    </div>
</x-admin-layout>
