@php $voter = $voter ?? null; @endphp

<div class="mb-3">
    <x-input-label for="nama" value="Nama" />
    <x-text-input id="nama" name="nama" value="{{ old('nama', $voter?->nama) }}" required autofocus />
    <x-input-error :messages="$errors->get('nama')" class="mt-1" />
</div>

<div class="mb-3">
    <x-input-label for="nik" value="NIK (16 digit)" />
    <x-text-input id="nik" name="nik" value="{{ old('nik') }}" maxlength="16"
                  placeholder="{{ $voter ? 'Kosongkan jika tidak diubah' : '' }}" {{ $voter ? '' : 'required' }} />
    <x-input-error :messages="$errors->get('nik')" class="mt-1" />
</div>

<div class="row g-2 mb-3">
    <div class="col-md-4">
        <x-input-label for="tps_id" value="TPS" />
        <select id="tps_id" name="tps_id" class="form-select" required>
            <option value="">-- Pilih TPS --</option>
            @forelse ($tpsList as $tpsItem)
                <option value="{{ $tpsItem->id }}" @selected(old('tps_id', $voter?->tps_id) === $tpsItem->id)>
                    TPS {{ $tpsItem->nomor }} - {{ $tpsItem->nama_lokasi }}
                </option>
            @empty
                <option value="" disabled>Belum ada TPS, tambahkan dulu di menu Data TPS</option>
            @endforelse
        </select>
        <x-input-error :messages="$errors->get('tps_id')" class="mt-1" />
    </div>
    <div class="col-md-4">
        <x-input-label for="rt" value="RT" />
        <x-text-input id="rt" name="rt" value="{{ old('rt', $voter?->rt) }}" />
    </div>
    <div class="col-md-4">
        <x-input-label for="rw" value="RW" />
        <x-text-input id="rw" name="rw" value="{{ old('rw', $voter?->rw) }}" />
    </div>
</div>

<div class="mb-3">
    <x-input-label for="status_terdaftar" value="Status Terdaftar" />
    <select id="status_terdaftar" name="status_terdaftar" class="form-select">
        @foreach (['terdaftar', 'tidak_terdaftar', 'pindah'] as $status)
            <option value="{{ $status }}" @selected(old('status_terdaftar', $voter?->status_terdaftar) === $status)>
                {{ str_replace('_', ' ', ucfirst($status)) }}
            </option>
        @endforeach
    </select>
</div>
