<?= $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">Edit Jurusan: <?= $jurusan['nama_jurusan'] ?></h4>
                </div>
                <div class="card-body p-4">
                    <form action="<?= base_url('admin/jurusan/update') ?>" method="post" enctype="multipart/form-data">
                        <?= csrf_field() ?>
                        <input type="hidden" name="id_jurusan" value="<?= $jurusan['id_jurusan'] ?>">
                        <input type="hidden" name="slug" value="<?= $jurusan['slug'] ?>">

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold">Nama Jurusan</label>
                                <input type="text" name="nama_jurusan" class="form-control" value="<?= $jurusan['nama_jurusan'] ?>" required>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold">Kepala Program (Kaprog)</label>
                                <input type="text" name="kaprog" class="form-control" value="<?= $jurusan['kaprog'] ?>">
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold text-success">Logo Jurusan</label>
                                <input type="file" name="logo_jurusan" class="form-control">
                                <small class="text-muted">File saat ini: <?= $jurusan['logo_jurusan'] ?></small>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold text-success">Foto Kegiatan (Guru/Siswa)</label>
                                <input type="file" name="foto_kegiatan" class="form-control">
                                <small class="text-muted">File saat ini: <?= $jurusan['foto_kegiatan'] ?></small>
                            </div>
                        </div>

                        <div class="form-group mb-3">
                            <label class="fw-bold">Deskripsi Singkat Jurusan</label>
                            <textarea name="deskripsi" class="form-control" rows="5"><?= $jurusan['deskripsi'] ?></textarea>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold text-success">Visi Jurusan</label>
                                <textarea name="visi_jurusan" class="form-control" rows="4"><?= $jurusan['visi_jurusan'] ?></textarea>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="fw-bold text-success">Misi Jurusan</label>
                                <textarea name="misi_jurusan" class="form-control" rows="4"><?= $jurusan['misi_jurusan'] ?></textarea>
                            </div>
                        </div>
                        <div class="form-group mb-3">
    <label class="fw-bold text-success">Guru Produktif (Gunakan Enter untuk nama baru)</label>
    <textarea name="guru_produktif" class="form-control" rows="4" placeholder="Contoh:&#10;Azis Maulana, S.Kom"><?= $jurusan['guru_produktif'] ?></textarea>
    <small class="text-muted italic">*Satu nama per baris (tekan Enter)</small>
</div>

                        <div class="mt-4">
                            <button type="submit" class="btn btn-success btn-lg px-5 shadow-sm">SIMPAN PERUBAHAN</button>
                            <a href="<?= base_url('jurusan/'.$jurusan['slug']) ?>" class="btn btn-secondary btn-lg px-5">BATAL</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row justify-content-center mt-4">
    <div class="col-lg-10">
        <div class="card shadow border-0">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fa fa-image"></i> Kelola Galeri Foto Kegiatan</h5>
            </div>
            <div class="card-body p-4">
                <form action="<?= base_url('admin/jurusan/upload_galeri') ?>" method="post" enctype="multipart/form-data" class="mb-4">
                    <input type="hidden" name="id_jurusan" value="<?= $jurusan['id_jurusan'] ?>">
                    <input type="hidden" name="slug" value="<?= $jurusan['slug'] ?>">
                    <label class="fw-bold">Tambah Foto Kegiatan (Bisa pilih banyak sekaligus)</label>
                    <div class="input-group">
                        <input type="file" name="galeri_foto[]" class="form-control" multiple required>
                        <button type="submit" class="btn btn-primary px-4">UPLOAD</button>
                    </div>
                    <small class="text-muted">Format: jpg, jpeg, png. Ukuran max 2MB per foto.</small>
                </form>

                <hr>

                <div class="row">
                    <?php 
                    $db = \Config\Database::connect();
                    $galeri = $db->table('jurusan_galeri')->where('id_jurusan', $jurusan['id_jurusan'])->get()->getResultArray();
                    if ($galeri) :
                        foreach ($galeri as $g) : ?>
                        <div class="col-md-3 mb-3">
                            <div class="position-relative">
                                <img src="<?= base_url('assets/img/kegiatan/' . $g['foto']) ?>" class="img-fluid rounded shadow-sm" style="height: 150px; width: 100%; object-fit: cover;">
                                <a href="<?= base_url('admin/jurusan/hapus_galeri/' . $g['id_galeri'] . '/' . $jurusan['slug']) ?>" 
                                   class="btn btn-danger btn-sm position-absolute top-0 end-0 m-1" 
                                   onclick="return confirm('Hapus foto ini?')">
                                    <i class="fa fa-trash"></i>
                                </a>
                            </div>
                        </div>
                    <?php endforeach; else: ?>
                        <div class="col-12 text-center">
                            <p class="text-muted italic">Belum ada foto galeri.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>