<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Edit Berita') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-xl sm:rounded-2xl">
                <div class="p-8">
                    <!-- Header Section -->
                    <div class="mb-8">
                        <h2 class="text-3xl font-bold text-gray-800 mb-2">Edit Berita</h2>
                        <p class="text-gray-600">Perbarui informasi berita</p>
                    </div>

                    <form action="{{ route('beritas.update', $berita) }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        @method('PUT')
                        
                        <!-- News Information -->
                        <div class="bg-gray-50 rounded-xl p-6 mb-8">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">Informasi Berita</h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Judul Berita</label>
                                    <input type="text" name="judul" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" value="{{ old('judul', $berita->judul) }}" placeholder="Masukkan judul berita" required>
                                    @error('judul')
                                        <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Kategori</label>
                                    <select name="kategori" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" required>
                                        <option value="">Pilih Kategori</option>
                                        <option value="Akademik" {{ old('kategori', $berita->kategori) == 'Akademik' ? 'selected' : '' }}>Akademik</option>
                                        <option value="Non-Akademik" {{ old('kategori', $berita->kategori) == 'Non-Akademik' ? 'selected' : '' }}>Non-Akademik</option>
                                        <option value="Kegiatan Sekolah" {{ old('kategori', $berita->kategori) == 'Kegiatan Sekolah' ? 'selected' : '' }}>Kegiatan Sekolah</option>
                                        <option value="Pengumuman" {{ old('kategori', $berita->kategori) == 'Pengumuman' ? 'selected' : '' }}>Pengumuman</option>
                                        <option value="Prestasi" {{ old('kategori', $berita->kategori) == 'Prestasi' ? 'selected' : '' }}>Prestasi</option>
                                    </select>
                                    @error('kategori')
                                        <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="mt-6">
                                <label class="block text-sm font-medium text-gray-700 mb-2">Ringkasan</label>
                                <textarea name="ringkasan" rows="3" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" placeholder="Ringkasan singkat berita" required>{{ old('ringkasan', $berita->ringkasan) }}</textarea>
                                @error('ringkasan')
                                    <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <!-- Content Section -->
                        <div class="bg-gray-50 rounded-xl p-6 mb-8">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">Konten Berita</h3>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Isi Berita</label>
                                <textarea name="isi" rows="10" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" placeholder="Tulis isi berita lengkap di sini..." required>{{ old('isi', $berita->isi) }}</textarea>
                                @error('isi')
                                    <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <!-- Media Section -->
                        <div class="bg-gray-50 rounded-xl p-6 mb-8">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">Media</h3>
                            
                            <!-- Current Image -->
                            @if($berita->gambar)
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Gambar Saat Ini</label>
                                    <div class="flex items-center space-x-4">
                                        <img src="{{ asset('storage/' . $berita->gambar) }}" 
                                             alt="Current Image" 
                                             class="w-32 h-32 object-cover rounded-lg border border-gray-300">
                                        <div>
                                            <p class="text-sm text-gray-600">File: {{ basename($berita->gambar) }}</p>
                                            <p class="text-xs text-gray-500">Upload: {{ $berita->updated_at->format('d M Y H:i') }}</p>
                                        </div>
                                    </div>
                                </div>
                            @endif
                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">
                                    {{ $berita->gambar ? 'Ganti Gambar Berita' : 'Gambar Berita' }}
                                </label>
                                <input type="file" name="gambar" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" accept="image/*">
                                <p class="text-sm text-gray-500 mt-1">Format: JPG, PNG, GIF. Maksimal 5MB. {{ $berita->gambar ? 'Kosongkan jika tidak ingin mengubah gambar.' : '' }}</p>
                                @error('gambar')
                                    <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <!-- Publishing Information -->
                        <div class="bg-gray-50 rounded-xl p-6 mb-8">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">Informasi Publikasi</h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Penulis</label>
                                    <input type="text" name="penulis" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" value="{{ old('penulis', $berita->penulis) }}" placeholder="Nama penulis berita" required>
                                    @error('penulis')
                                        <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Status Publikasi</label>
                                    <select name="status" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors" required>
                                        <option value="draft" {{ old('status', $berita->status) == 'draft' ? 'selected' : '' }}>Draft</option>
                                        <option value="published" {{ old('status', $berita->status) == 'published' ? 'selected' : '' }}>Published</option>
                                    </select>
                                    @error('status')
                                        <div class="text-red-600 text-sm mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <!-- Action Buttons -->
                        <div class="flex items-center justify-end space-x-4 pt-6 border-t border-gray-200">
                            <a href="{{ route('beritas.index') }}" class="inline-flex items-center px-6 py-3 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors">
                                <i class="fas fa-arrow-left mr-2"></i>
                                Kembali
                            </a>
                            <button type="submit" class="inline-flex items-center px-6 py-3 text-sm font-medium text-white bg-red-600 rounded-lg hover:bg-red-700 transition-colors">
                                <i class="fas fa-save mr-2"></i>
                                Update Berita
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout> 
