<?= $this->extend('layout/default') ?>

<?= $this->section('content') ?>
<div class="container pt-100 pb-100">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card shadow border-0">
                <div class="card-header bg-success text-white">
                    <h4 class="mb-0"><i class="fa fa-edit"></i> Edit Berita Lengkap</h4>
                </div>
                <div class="card-body p-4">
                    <form action="<?= base_url('admin/berita/update') ?>" method="post" enctype="multipart/form-data">
                        <?= csrf_field() ?>
                        
                        <input type="hidden" name="id_berita" value="<?= $berita['id_berita'] ?>">
                        <input type="hidden" name="gambarLama" value="<?= $berita['gambar'] ?>">

                        <div class="form-group mb-3">
                            <label class="fw-bold">Judul Berita</label>
                            <input type="text" name="judul" class="form-control" value="<?= $berita['judul'] ?>" placeholder="Masukkan judul berita..." required>
                        </div>

                        <div class="row">
                            <!-- Cari bagian input file gambar dan ubah menjadi seperti ini -->
<div class="form-group mb-3">
    <label class="fw-bold">Ganti Foto Kegiatan (Pilih 1-4 Foto untuk Kolase Baru)</label>
    <input type="file" name="gambar[]" class="form-control" accept="image/*" multiple>
    <input type="hidden" name="gambarLama" value="<?= $berita['gambar'] ?>">
    <small class="text-muted fst-italic">* Biarkan kosong jika tidak ingin mengubah foto layout.</small>
</div>
                            <div class="col-md-4 mb-3">
                                <label class="fw-bold text-success">Status Penerbitan</label>
                                <select name="status" class="form-control" required>
                                    <option value="publish" <?= $berita['status'] == 'publish' ? 'selected' : '' ?>>Publikasikan (Muncul di Web)</option>
                                    <option value="draft" <?= $berita['status'] == 'draft' ? 'selected' : '' ?>>Draft (Hanya Admin)</option>
                                </select>
                            </div>
                            <div class="col-md-4 mb-3">
                                <label class="fw-bold text-success">Tanggal Posting</label>
                                <input type="date" name="tanggal_post" class="form-control" value="<?= date('Y-m-d', strtotime($berita['tanggal_post'])) ?>" required>
                            </div>
                        </div>

                        <div class="form-group mb-3">
                            <label class="fw-bold text-success">Keterangan Foto (Caption)</label>
                            <input type="text" name="caption_foto" class="form-control" value="<?= $berita['caption_foto'] ?>" placeholder="Contoh: Suasana gotong royong di lingkungan sekolah...">
                            <small class="text-muted fst-italic">* Keterangan ini akan muncul tepat di bawah foto berita.</small>
                        </div>

                        <div class="form-group mb-3">
                            <label class="fw-bold text-success">Ringkasan (Muncul di Halaman Depan)</label>
                            <textarea name="ringkasan" class="form-control" rows="3" placeholder="Tulis ringkasan singkat..."><?= $berita['ringkasan'] ?></textarea>
                            <small class="text-muted">Gunakan 1-2 kalimat pengantar agar tampilan kartu berita rapi.</small>
                        </div>

                        <div class="form-group mb-3">
                            <label class="fw-bold">Isi Berita Lengkap</label>
                            <textarea id="summernote" name="isi_berita" class="form-control" required><?= $berita['isi_berita'] ?></textarea>
                        </div>

                        <div class="mt-4 border-top pt-3 text-right">
                            <a href="<?= base_url('admin/berita') ?>" class="btn btn-secondary px-4 mr-2">
                                <i class="fa fa-times"></i> BATAL
                            </a>
                            <button type="submit" class="btn btn-success px-5 shadow-sm">
                                <i class="fa fa-save"></i> SIMPAN PERUBAHAN
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>

<script>
    $(document).ready(function() {
        $('#summernote').summernote({
            placeholder: 'Tuliskan detail berita di sini... Gunakan ENTER untuk jeda paragraf.',
            tabsize: 2,
            height: 350,
            toolbar: [
                ['style', ['style']],
                ['font', ['bold', 'underline', 'clear']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ]
        });
    });
</script>
<?= $this->endSection() ?>