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

<div class="mb-3">
    <x-input-label for="kecamatan_id" value="Kecamatan" />
    <select id="kecamatan_id" name="kecamatan_id" class="form-select" required>
        <option value="">-- Pilih Kecamatan --</option>
        @foreach ($kecamatanList as $kec)
            <option value="{{ $kec->id }}" @selected(old('kecamatan_id', $desa?->kecamatan_id) === $kec->id)>
                {{ $kec->nama }} ({{ $kec->kabupaten->nama }})
            </option>
        @endforeach
    </select>
    <x-input-error :messages="$errors->get('kecamatan_id')" class="mt-1" />
</div>

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

<div class="mb-3">
    <x-input-label for="tanggal_pilkades" value="Tanggal Pilkades (opsional)" />
    <input type="date" id="tanggal_pilkades" name="tanggal_pilkades" class="form-control"
           value="{{ old('tanggal_pilkades', $desa?->tanggal_pilkades?->format('Y-m-d')) }}">
    <x-input-error :messages="$errors->get('tanggal_pilkades')" class="mt-1" />
</div>

<div class="mb-3">
    <x-input-label for="logo" value="Logo Desa" />
    <input type="file" id="logo" name="logo" class="form-control" accept="image/*">
    <x-input-error :messages="$errors->get('logo')" class="mt-1" />
    @if ($desa?->logo)
        <img src="{{ Storage::url($desa->logo) }}" alt="Logo" class="mt-2" style="height: 60px;">
    @endif
</div>

<div class="mb-3 form-check form-switch">
    <input type="checkbox" class="form-check-input" id="is_active" name="is_active" value="1"
           {{ old('is_active', $desa?->is_active ?? true) ? 'checked' : '' }}>
    <label class="form-check-label" for="is_active">Aktif</label>
</div>
