<?= $this->extend('v_template/layout') ?>
<?= $this->section('content') ?>

<?php $is_edit = isset($dokumen_edit); ?>

<div class="row mb-4 align-items-center">
    <div class="col-md-6">
        <h4 class="fw-bold text-success"><i class="fa-solid <?= $is_edit ? 'fa-pen-to-square' : 'fa-cloud-arrow-up' ?> me-2"></i> <?= $is_edit ? 'Edit Dokumen Arsip' : 'Unggah Dokumen Baru' ?></h4>
    </div>
    <div class="col-md-6 text-md-end mt-3 mt-md-0">
        <a href="<?= base_url('arsip') ?>" class="btn btn-outline-secondary rounded-pill shadow-sm"><i class="fa-solid fa-arrow-left me-2"></i> Batal</a>
    </div>
</div>

<div class="card shadow-sm border-0">
    <div class="card-body p-4">
        <form action="<?= $is_edit ? base_url('arsip/update/'.$dokumen_edit['id_dokumen']) : base_url('arsip/simpan') ?>" method="POST" enctype="multipart/form-data">
            <div class="mb-3">
                <label class="form-label fw-bold">Judul Dokumen</label>
                <input type="text" class="form-control" name="judul_dokumen" value="<?= $is_edit ? $dokumen_edit['judul_dokumen'] : '' ?>" required>
            </div>
            <div class="mb-3">
                <label class="form-label fw-bold">Kategori</label>
                <select class="form-select" name="kategori" required>
                    <option value="Laporan Lapangan" <?= ($is_edit && $dokumen_edit['kategori'] == 'Laporan Lapangan') ? 'selected' : '' ?>>Laporan Lapangan</option>
                    <option value="Surat Keputusan (SK)" <?= ($is_edit && $dokumen_edit['kategori'] == 'Surat Keputusan (SK)') ? 'selected' : '' ?>>Surat Keputusan (SK)</option>
                    <option value="Peta Spasial" <?= ($is_edit && $dokumen_edit['kategori'] == 'Peta Spasial') ? 'selected' : '' ?>>Peta Spasial</option>
                    <option value="Lainnya" <?= ($is_edit && $dokumen_edit['kategori'] == 'Lainnya') ? 'selected' : '' ?>>Lainnya</option>
                </select>
            </div>
            <div class="mb-4">
                <label class="form-label fw-bold">Ganti File Berkas <?= $is_edit ? '<span class="text-muted fw-normal">(Opsional)</span>' : '' ?></label>
                <input class="form-control" type="file" name="file_dokumen" <?= $is_edit ? '' : 'required' ?>>
                <?php if($is_edit): ?>
                    <small class="text-danger">*Biarkan kosong jika tidak ingin mengganti file asli.</small>
                <?php endif; ?>
            </div>
            <hr class="mb-4">
            <div class="text-end">
                <button type="submit" class="btn btn-success px-4 rounded-pill shadow-sm"><i class="fa-solid fa-save me-2"></i> Simpan Dokumen</button>
            </div>
        </form>
    </div>
</div>
<?= $this->endSection() ?>