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

<?php $is_edit = isset($titik_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' : 'fa-plus' ?> me-2"></i> <?= $is_edit ? 'Edit Titik Peta' : 'Tambah Titik Peta' ?></h4>
    </div>
</div>

<div class="card shadow-sm border-0">
    <div class="card-body p-4">
        <form action="<?= base_url('peta/simpan') ?>" method="POST">
            <?php if($is_edit): ?> <input type="hidden" name="id_titik" value="<?= $titik_edit['id_titik'] ?>"> <?php endif; ?>
            
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="fw-bold">Nama Lokasi</label>
                    <input type="text" name="nama_lokasi" class="form-control" value="<?= $is_edit ? $titik_edit['nama_lokasi'] : '' ?>" required>
                </div>
                <div class="col-md-6 mb-3">
                    <label class="fw-bold">Kategori</label>
                    <select name="kategori" class="form-select" required>
                        <option value="Kantor" <?= ($is_edit && $titik_edit['kategori'] == 'Kantor') ? 'selected' : '' ?>>Kantor KPH</option>
                        <option value="Rawan Karhutla" <?= ($is_edit && $titik_edit['kategori'] == 'Rawan Karhutla') ? 'selected' : '' ?>>Titik Rawan Karhutla</option>
                        <option value="Rehabilitasi" <?= ($is_edit && $titik_edit['kategori'] == 'Rehabilitasi') ? 'selected' : '' ?>>Area Rehabilitasi</option>
                        <option value="Patroli" <?= ($is_edit && $titik_edit['kategori'] == 'Patroli') ? 'selected' : '' ?>>Titik Patroli Biasa</option>
                    </select>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="fw-bold">Latitude (Garis Lintang)</label>
                    <input type="text" name="latitude" class="form-control" placeholder="Contoh: 2.9698" value="<?= $is_edit ? $titik_edit['latitude'] : '' ?>" required>
                </div>
                <div class="col-md-6 mb-3">
                    <label class="fw-bold">Longitude (Garis Bujur)</label>
                    <input type="text" name="longitude" class="form-control" placeholder="Contoh: 99.6309" value="<?= $is_edit ? $titik_edit['longitude'] : '' ?>" required>
                </div>
            </div>
            <div class="mb-4">
                <label class="fw-bold">Deskripsi Tambahan</label>
                <textarea name="deskripsi" class="form-control" rows="3"><?= $is_edit ? $titik_edit['deskripsi'] : '' ?></textarea>
            </div>
            <div class="text-end">
                <a href="<?= base_url('peta/kelola') ?>" class="btn btn-light rounded-pill me-2">Batal</a>
                <button type="submit" class="btn btn-success rounded-pill px-4"><i class="fa-solid fa-save me-1"></i> Simpan Titik Peta</button>
            </div>
        </form>
    </div>
</div>
<?= $this->endSection() ?>