<x-app-layout>
    <x-slot name="header">
        <h2 class="h4 mb-0">Master Admin Desa</h2>
    </x-slot>

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Nama</th>
                        <th>Email</th>
                        <th>Desa</th>
                        <th>Status</th>
                        <th>Login Terakhir</th>
                        <th class="text-end">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($admins as $admin)
                        <tr>
                            <td>{{ $admin->name }}</td>
                            <td>{{ $admin->email }}</td>
                            <td>{{ $admin->desa?->nama }} ({{ $admin->desa?->kecamatan?->kabupaten?->nama }})</td>
                            <td>
                                <span class="badge {{ $admin->is_active ? 'bg-success' : 'bg-secondary' }}">
                                    {{ $admin->is_active ? 'Aktif' : 'Nonaktif' }}
                                </span>
                            </td>
                            <td>{{ $admin->last_login_at?->diffForHumans() ?? '-' }}</td>
                            <td class="text-end">
                                <form action="{{ route('super-admin.admin-desa.toggle-active', $admin) }}" method="POST" class="d-inline">
                                    @csrf
                                    <button class="btn btn-sm btn-outline-secondary">
                                        {{ $admin->is_active ? 'Nonaktifkan' : 'Aktifkan' }}
                                    </button>
                                </form>
                                <form action="{{ route('super-admin.admin-desa.reset-password', $admin) }}" method="POST" class="d-inline">
                                    @csrf
                                    <button class="btn btn-sm btn-outline-warning">Reset Password</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">Belum ada Admin Desa.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

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