@extends('layouts.admin')
@section('title', $official->exists ? 'Edit Perangkat' : 'Tambah Perangkat')
@section('page-title', $official->exists ? 'Edit Perangkat Desa' : 'Tambah Perangkat Desa')

@section('content')
<div class="max-w-lg">
    <form method="POST" action="{{ $official->exists ? route('admin.perangkat.update', $official->id) : route('admin.perangkat.store') }}" enctype="multipart/form-data" class="card-admin space-y-4">
        @csrf
        @if($official->exists) @method('PUT') @endif

        <div><label class="form-label">Nama *</label><input name="nama" value="{{ old('nama', $official->nama) }}" class="form-input" required></div>
        <div><label class="form-label">Jabatan *</label><input name="jabatan" value="{{ old('jabatan', $official->jabatan) }}" class="form-input" required placeholder="Kepala Desa, Sekretaris Desa, dst."></div>
        <div><label class="form-label">Tempat, Tanggal Lahir (TTL)</label><input name="ttl" value="{{ old('ttl', $official->ttl) }}" class="form-input" placeholder="Contoh: Suka Baru, 11 Februari 1982"></div>
        <div><label class="form-label">Urutan Tampil *</label><input type="number" name="urutan" value="{{ old('urutan', $official->urutan ?? 1) }}" class="form-input" required min="1"></div>
        <div>
            <label class="form-label">Foto</label>
            @if($official->foto_url)
                <img src="{{ $official->foto_url }}" class="w-20 h-20 rounded-full object-cover mb-2">
            @endif
            <input type="file" name="foto" accept="image/*" class="form-input">
            <p class="text-xs text-gray-400 mt-1">JPG/PNG/WebP, maks 2MB</p>
        </div>

        @if($errors->any())
            <div class="bg-red-50 border border-red-200 rounded-lg p-3">
                @foreach($errors->all() as $err)<p class="text-red-600 text-sm">{{ $err }}</p>@endforeach
            </div>
        @endif

        <div class="flex gap-3 pt-2">
            <button type="submit" class="btn-primary">💾 {{ $official->exists ? 'Perbarui' : 'Simpan' }}</button>
            <a href="{{ route('admin.perangkat.index') }}" class="btn-secondary">Batal</a>
        </div>
    </form>
</div>
@endsection
