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

<div class="row justify-content-center">
    <div class="col-md-8">

        <div class="card shadow-sm border-0">
            <div class="card-header bg-warning text-dark d-flex align-items-center">
                <i class="fas fa-project-diagram me-2"></i>
                <b>Edit Jurusan / Program</b>
            </div>

            <?php if ($locked): ?>
                <div class="alert alert-warning rounded-0 mb-0">
                    <i class="fas fa-lock me-1"></i>
                    Jurusan ini <b>sudah digunakan dalam proses PPDB</b>.
                    Data tidak dapat diubah untuk menjaga konsistensi seleksi.
                </div>
            <?php endif; ?>

            <form action="<?= site_url('master/major/update/'.$major['id']) ?>" method="post">
                <?= csrf_field() ?>

                <div class="card-body">

                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <label class="font-weight-bold">Kode Jurusan</label>
                            <input type="text"
                                   class="form-control"
                                   value="<?= esc($major['code']) ?>"
                                   readonly>
                            <small class="text-muted">
                                Kode bersifat permanen dan tidak dapat diubah
                            </small>
                        </div>

                        <div class="form-group col-md-8">
                            <label class="font-weight-bold">Nama Jurusan</label>
                            <input type="text"
                                   name="name"
                                   class="form-control"
                                   value="<?= esc($major['name']) ?>"
                                   <?= $locked ? 'disabled' : '' ?>
                                   required>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <label>Level</label>
                            <select name="level"
                                    class="form-control"
                                    <?= $locked ? 'disabled' : '' ?>>
                                <?php foreach (['SD','SMP','SMA'] as $lvl): ?>
                                    <option value="<?= $lvl ?>"
                                        <?= $major['level']==$lvl?'selected':'' ?>>
                                        <?= $lvl ?>
                                    </option>
                                <?php endforeach ?>
                            </select>
                        </div>

                        <div class="form-group col-md-4">
                            <label>Kuota</label>
                            <input type="number"
                                   name="quota"
                                   class="form-control"
                                   value="<?= $major['quota'] ?>"
                                   <?= $locked ? 'disabled' : '' ?>>
                        </div>

                        <div class="form-group col-md-4">
                            <label>Status</label>
                            <select name="is_active"
                                    class="form-control"
                                    <?= $locked ? 'disabled' : '' ?>>
                                <option value="1" <?= $major['is_active']==1?'selected':'' ?>>Aktif</option>
                                <option value="0" <?= $major['is_active']==0?'selected':'' ?>>Nonaktif</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label>Deskripsi</label>
                        <textarea name="description"
                                  rows="3"
                                  class="form-control"
                                  <?= $locked ? 'disabled' : '' ?>><?= esc($major['description']) ?></textarea>
                    </div>

                </div>

                <div class="card-footer d-flex justify-content-between">
                    <a href="<?= site_url('master/major') ?>" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> Kembali
                    </a>

                    <?php if (!$locked): ?>
                        <button class="btn btn-warning text-dark fw-bold">
                            <i class="fas fa-save"></i> Update Jurusan
                        </button>
                    <?php else: ?>
                        <span class="text-muted fst-italic">
                            <i class="fas fa-lock"></i> Edit dinonaktifkan
                        </span>
                    <?php endif; ?>
                </div>

            </form>
        </div>

    </div>
</div>

<?= $this->endSection() ?>
