<x-app-layout>
    <x-slot name="header">
        <div class="d-flex justify-content-between align-items-center">
            <h2 class="h4 mb-0">Data Pemilih</h2>
            <div>
                <a href="{{ route('admin-desa.voter.import.show') }}" class="btn btn-outline-secondary btn-sm">Impor CSV</a>
                <a href="{{ route('admin-desa.voter.create') }}" class="btn btn-primary btn-sm">+ Tambah Pemilih</a>
            </div>
        </div>
    </x-slot>

    <form method="GET" class="mb-3">
        <input type="text" name="q" class="form-control" placeholder="Cari nama..." value="{{ request('q') }}">
    </form>

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Nama</th>
                        <th>NIK</th>
                        <th>TPS</th>
                        <th>RT/RW</th>
                        <th>Status</th>
                        <th class="text-end">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($voters as $voter)
                        <tr>
                            <td>{{ $voter->nama }}</td>
                            <td><code>{{ \App\Modules\Pilkades\Models\Voter::maskNik($voter->nik) }}</code></td>
                            <td>{{ $voter->tps ? 'TPS '.$voter->tps->nomor.' - '.$voter->tps->nama_lokasi : '-' }}</td>
                            <td>{{ $voter->rt }}/{{ $voter->rw }}</td>
                            <td>
                                <span class="badge bg-info text-dark">{{ str_replace('_', ' ', $voter->status_terdaftar) }}</span>
                            </td>
                            <td class="text-end">
                                <a href="{{ route('admin-desa.voter.edit', $voter) }}" class="btn btn-sm btn-outline-secondary">Edit</a>
                                <form action="{{ route('admin-desa.voter.destroy', $voter) }}" method="POST" class="d-inline" onsubmit="return confirm('Hapus data pemilih 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 pemilih.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

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