<?= $this->extend('layout/default') ?>
<?= $this->section('content') ?>
<div class="container-fluid px-4">
    <h1 class="mt-4">Tambah Personil</h1>
    <div class="card mb-4 col-lg-8">
        <div class="card-body shadow">
            <form action="<?= base_url('admin/struktur/simpan') ?>" method="post" enctype="multipart/form-data">
                <?= csrf_field() ?>
                <div class="mb-3">
                    <label class="form-label">Nama Lengkap & Gelar</label>
                    <input type="text" name="nama" class="form-control" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">Jabatan Spesifik</label>
                    <input type="text" name="jabatan" class="form-control" required placeholder="Contoh: Staf Kesiswaan">
                </div>
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Level Hirarki</label>
                        <select name="level" class="form-select" required>
                            <option value="1">Level 1 (Kepala Sekolah)</option>
                            <option value="2">Level 2 (TU / Komite)</option>
                            <option value="3">Level 3 (Para Wakasek)</option>
                            <option value="4" selected>Level 4 (Staf / Anggota)</option>
                        </select>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Pilih Atasan (Hanya untuk Staf)</label>
                        <select name="parent_id" class="form-select">
                            <option value="0">-- Tanpa Atasan (Pimpinan) --</option>
                            <?php 
                            $db = \Config\Database::connect();
                            $wakaseks = $db->table('struktur')->where('level', '3')->get()->getResultArray();
                            foreach ($wakaseks as $w) : ?>
                                <option value="<?= $w['id_struktur'] ?>"><?= $w['jabatan'] ?> (<?= $w['nama'] ?>)</option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Urutan Tampil</label>
                        <input type="number" name="urutan" class="form-control" value="1">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Foto</label>
                        <input type="file" name="foto" class="form-control">
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">Simpan</button>
                <a href="<?= base_url('admin/struktur') ?>" class="btn btn-secondary">Batal</a>
            </form>
        </div>
    </div>
</div>
<?= $this->endSection() ?>