<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">Edit Artikel Edukasi</h2>
                    <p class="text-sm text-gray-400 font-medium mt-0.5">Ubah dan perbarui konten literasi bisnis untuk kebutuhan UMKM Tempe Zhi.</p>
                </div>
                <div>
                    <a href="{{ route('admin.articles.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 overflow-hidden shadow-sm rounded-2xl p-6 md:p-8 border border-gray-100">
                <form action="{{ route('admin.articles.update', $article->id) }}" method="POST" enctype="multipart/form-data" class="space-y-6">
                    @csrf
                    @method('PUT')
                    <div class="space-y-2">
                        <label for="title" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Judul Artikel</label>
                        <input type="text" 
                               name="title" 
                               id="title" 
                               value="{{ old('title', $article->title) }}"
                               placeholder="Masukkan judul artikel..."
                               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"
                               required>
                    </div>

                    <div class="space-y-2">
                        <label for="slug" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Slug / Link URL</label>
                        <div class="flex items-center text-sm">
                            <span class="bg-gray-50 px-4 py-3 rounded-l-xl border border-r-0 border-gray-200 text-gray-400 font-medium">tempezhi.com/blog/</span>
                            <input type="text" 
                                   name="slug" 
                                   id="slug" 
                                   value="{{ old('slug', $article->slug) }}" 
                                   class="flex-1 px-4 py-3 rounded-r-xl border border-gray-200 bg-gray-50/50 text-gray-500 font-medium focus:outline-none"
                                   readonly>
                        </div>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="space-y-2">
                            <label for="source_url" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Sumber Artikel (Link Eksternal)</label>
                            <input type="url" 
                                   name="source_url" 
                                   id="source_url"
                                   value="{{ old('source_url', $article->source_url) }}" 
                                   placeholder="https://website-sumber.com/artikel-asli"
                                   class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-medium text-blue-600 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all placeholder:text-gray-300">
                        </div>

                        <div class="space-y-2">
                            <label for="status" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Status Artikel</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', $article->status) == 'aktif' ? 'selected' : '' }}>Aktif (Tampilkan)</option>
                                <option value="non-aktif" {{ old('status', $article->status) == 'non-aktif' ? 'selected' : '' }}>Non-aktif (Sembunyikan)</option>
                            </select>
                        </div>
                    </div>

                    <div class="space-y-3">
                        <label class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Foto Sampul (Cover)</label>
                        
                        @if($article->image)
                            <div class="relative w-48 h-32 group">
                                <img src="{{ asset('storage/' . $article->image) }}" class="w-full h-full object-cover rounded-xl border border-gray-100 shadow-sm">
                                <div class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity rounded-xl flex items-center justify-center text-white text-[10px] font-bold">GAMBAR SAAT INI</div>
                            </div>
                        @endif

                        <input type="file" 
                               name="image" 
                               class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm font-medium text-gray-400 focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all bg-white file:mr-4 file:py-1 file:px-3 file:rounded-xl file:border-0 file:text-xs file:font-bold file:bg-gray-50 file:text-gray-600 hover:file:bg-gray-100">
                        <p class="text-[11px] text-gray-400 italic">*Biarkan kosong jika tidak ingin mengganti foto.</p>
                    </div>

                    <div class="space-y-2">
                        <label for="content" class="text-xs font-bold text-gray-400 uppercase tracking-wider block">Isi Artikel</label>
                        <textarea name="content" 
                                  id="content"
                                  rows="12" 
                                  class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm font-medium text-gray-700 leading-relaxed focus:ring-2 focus:ring-green-700/20 focus:border-green-700 transition-all">{{ old('content', $article->content) }}</textarea>
                    </div>

                    <div class="flex justify-end items-center gap-3 pt-4 border-t border-gray-50">
                        <a href="{{ route('admin.articles.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 transition-all active:scale-95">
                            Simpan Perubahan
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        const title = document.querySelector('#title');
        const slug = document.querySelector('#slug');

        title.addEventListener('keyup', function() {
            let preslug = title.value.toLowerCase();
            preslug = preslug.replace(/[^a-z0-9\s]/g, '');
            preslug = preslug.replace(/\s+/g, '-');
            slug.value = preslug;
        });
    </script>
</x-app-layout>