<x-app-layout>
    <div class="py-12 bg-gray-50 min-h-screen">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
            
            <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between bg-white p-6 rounded-2xl border border-gray-100 shadow-sm gap-4">
                <div>
                    <h2 class="text-2xl font-black text-gray-800 tracking-tight">Ubah Data Lokasi</h2>
                    <p class="text-sm text-gray-400 font-medium mt-0.5">Perbarui berkas informasi titik koordinat atau status operasional logistik distribusi Tempe Zhi.</p>
                </div>
                <div>
                    <a href="{{ route('admin.lokasi.index') }}"   class="inline-flex items-center gap-2 bg-white hover:bg-gray-50 text-gray-600 px-5 py-2.5 rounded-xl font-bold text-xs border border-gray-200 shadow-sm transition-all active:scale-95 whitespace-nowrap">
                        Kembali ke List
                    </a>
                </div>
            </div>

            <div class="bg-white shadow-sm rounded-2xl border border-gray-100 p-6 md:p-8">
                
                @if ($errors->any())
                    <div class="mb-6 p-4 bg-red-50 border-l-4 border-red-500 text-red-700 rounded-r-xl">
                        <ul class="list-disc list-inside text-sm font-medium">
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif

                <form action="{{ route('admin.lokasi.update', $lokasi->id) }}" method="POST" class="space-y-6">
                    @csrf 
                    @method('PUT')
                    
                    <div class="space-y-2">
                        <label for="nama_lokasi" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Nama Lokasi</label>
                        <input type="text" 
                               name="nama_lokasi" 
                               id="nama_lokasi"
                               value="{{ old('nama_lokasi', $lokasi->nama_lokasi) }}"
                               class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-800 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all" 
                               placeholder="Contoh: Rumah Production Utama Banjarbaru"
                               required>
                    </div>
                    
                    <div class="space-y-2">
                        <label for="alamat" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Alamat Lengkap</label>
                        <textarea name="alamat" 
                                  id="alamat"
                                  rows="3" 
                                  class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-800 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all" 
                                  placeholder="Tuliskan nama jalan, RT/RW, kelurahan, dan detail patokan operasional..."
                                  required>{{ old('alamat', $lokasi->alamat) }}</textarea>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="space-y-2">
                            <label for="latitude" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Latitude Koordinat</label>
                            <input type="text" 
                                   name="latitude" 
                                   id="latitude"
                                   value="{{ old('latitude', $lokasi->latitude) }}"
                                   class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-800 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all" 
                                   placeholder="-3.441234">
                        </div>

                        <div class="space-y-2">
                            <label for="longitude" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Longitude Koordinat</label>
                            <input type="text" 
                                   name="longitude" 
                                   id="longitude"
                                   value="{{ old('longitude', $lokasi->longitude) }}"
                                   class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-800 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all" 
                                   placeholder="114.831234">
                        </div>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="space-y-2">
                            <label for="tipe" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Tipe Penempatan</label>
                            <select name="tipe" 
                                    id="tipe"
                                    class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-700 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all bg-white">
                                <option value="produksi" {{ old('tipe', $lokasi->tipe) == 'produksi' ? 'selected' : '' }}>Rumah Produksi</option>
                                <option value="gudang_distribusi" {{ old('tipe', $lokasi->tipe) == 'gudang_distribusi' ? 'selected' : '' }}>Gudang Distribusi</option>
                            </select>
                        </div>

                        <div class="space-y-2">
                            <label for="status" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Status Operasional</label>
                            <select name="status" 
                                    id="status"
                                    class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-bold text-gray-700 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all bg-white">
                                <option value="aktif" {{ old('status', $lokasi->status) == 'aktif' ? 'selected' : '' }}>Aktif (Beroperasi)</option>
                                <option value="nonaktif" {{ old('status', $lokasi->status) == 'nonaktif' ? 'selected' : '' }}>Non-Aktif (Ditangguhkan)</option>
                            </select>
                        </div>
                    </div>

                    <div class="flex justify-end items-center gap-3 pt-6 border-t border-gray-50">
                        <a href="{{ route('admin.lokasi.index') }}" class="px-5 py-2.5 rounded-xl font-bold text-xs text-gray-500 hover:text-gray-700 transition-colors">
                            Batalkan
                        </a>
                        <button type="submit" class="inline-flex items-center gap-2 bg-green-700 hover:bg-green-800 text-white px-6 py-2.5 rounded-xl font-bold text-xs shadow-md shadow-green-700/10 transition-all active:scale-95">
                            Perbarui Data
                        </button>
                    </div>
                </form>
            </div>
            
        </div>
    </div>
</x-app-layout>