<x-app-layout>
    <x-slot name="header">
        <div class="d-flex justify-content-between align-items-center">
            <h2 class="h4 mb-0">Master Desa</h2>
            <a href="{{ route('super-admin.desa.create') }}" class="btn btn-primary btn-sm">+ Tambah Desa</a>
        </div>
    </x-slot>

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Nama Desa</th>
                        <th>Kecamatan</th>
                        <th>Kabupaten</th>
                        <th>URL</th>
                        <th>Status</th>
                        <th class="text-end">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($desa as $item)
                        <tr>
                            <td>{{ $item->nama }}</td>
                            <td>{{ $item->kecamatan->nama }}</td>
                            <td>{{ $item->kecamatan->kabupaten->nama }}</td>
                            <td>
                                <code>/{{ $item->kecamatan->kabupaten->slug }}/{{ $item->kecamatan->slug }}/{{ $item->slug }}</code>
                            </td>
                            <td>
                                @php
                                    $badge = match($item->status) {
                                        'published' => 'bg-success',
                                        'suspended' => 'bg-danger',
                                        default => 'bg-secondary',
                                    };
                                @endphp
                                <span class="badge {{ $badge }}">{{ ucfirst($item->status) }}</span>
                            </td>
                            <td class="text-end">
                                <a href="{{ route('super-admin.desa.edit', $item) }}" class="btn btn-sm btn-outline-secondary">Kelola</a>
                                <form action="{{ route('super-admin.desa.destroy', $item) }}" method="POST" class="d-inline" onsubmit="return confirm('Hapus desa ini?')">
                                    @csrf @method('DELETE')
                                    <button class="btn btn-sm btn-outline-danger">Hapus</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">Belum ada data Desa.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

    <div class="mt-3">{{ $desa->links() }}</div>
</x-app-layout>
