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

<style>
    /* ================== GLOBAL FORM STYLE ================== */
    .form-label, label {
        font-weight: 600;
        font-size: 0.85rem;
        color: #495057;
    }

    .form-control,
    .form-select {
        border-radius: 12px;
        padding: 10px 12px;
    }

    .form-control:focus,
    .form-select:focus {
        box-shadow: 0 0 0 .15rem rgba(13,110,253,.15);
        border-color: #0d6efd;
    }

    /* ================== CARD ================== */
    .card {
        border-radius: 18px;
    }

    .card-body {
        padding: 26px;
    }

    /* ================== SECTION ================== */
    .form-section {
        background: #f9fafb;
        padding: 22px;
        border-radius: 16px;
    }

    .section-title {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 18px;
        padding-bottom: 10px;
        border-bottom: 1px solid #e9ecef;
    }

    .section-title i {
        font-size: 1.1rem;
        color: #0d6efd;
    }

    .section-title h6 {
        margin: 0;
        font-weight: 700;
        font-size: .9rem;
        letter-spacing: .5px;
        text-transform: uppercase;
    }

    /* ================== FOOTER ================== */
    .card-footer {
        background: #fff;
        border-top: 1px solid #f0f0f0;
        padding: 16px 22px;
    }
</style>

<!-- HEADER -->
<div class="mb-4">
    <h4 class="fw-bold text-primary mb-1">
        <i class="fas fa-book me-2"></i> Master Mata Pelajaran
    </h4>
    <small class="text-muted">
        Tambah data mata pelajaran ke dalam sistem akademik
    </small>
</div>

<div class="card shadow-sm border-0">
    <form action="<?= site_url('master/subject/store') ?>" method="post">
        <?= csrf_field() ?>

        <div class="card-body">

            <!-- ERROR -->
            <?php if (session()->getFlashdata('errors')): ?>
                <div class="alert alert-danger alert-dismissible fade show mb-4">
                    <strong>Validasi gagal</strong>
                    <ul class="mb-0 mt-1">
                        <?php foreach (session('errors') as $err): ?>
                            <li><?= esc($err) ?></li>
                        <?php endforeach ?>
                    </ul>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif ?>

            <!-- SECTION -->
            <div class="form-section">

                <div class="section-title">
                    <i class="fas fa-layer-group"></i>
                    <h6>Informasi Mata Pelajaran</h6>
                </div>

                <div class="row g-3">

                    <div class="col-md-4">
                        <label class="form-label">
                            Kode Mapel <span class="text-danger">*</span>
                        </label>
                        <input type="text"
                               name="kode_mapel"
                               class="form-control"
                               placeholder="MTK01"
                               value="<?= old('kode_mapel') ?>"
                               required>
                        <small class="text-muted">Kode unik / tidak boleh sama</small>
                    </div>

                    <div class="col-md-8">
                        <label class="form-label">
                            Nama Mata Pelajaran <span class="text-danger">*</span>
                        </label>
                        <input type="text"
                               name="nama_mapel"
                               class="form-control"
                               placeholder="Matematika"
                               value="<?= old('nama_mapel') ?>"
                               required>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">
                            Kelompok <span class="text-danger">*</span>
                        </label>
                        <select name="kelompok" class="form-select" required>
                            <option value="">— Pilih Kelompok —</option>
                            <option value="Umum" <?= old('kelompok')=='Umum'?'selected':'' ?>>Umum</option>
                            <option value="Agama" <?= old('kelompok')=='Agama'?'selected':'' ?>>Agama</option>
                            <option value="Muatan Lokal" <?= old('kelompok')=='Muatan Lokal'?'selected':'' ?>>Muatan Lokal</option>
                        </select>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Status</label>
                        <select name="is_active" class="form-select">
                            <option value="1" <?= old('is_active',1)==1?'selected':'' ?>>Aktif</option>
                            <option value="0" <?= old('is_active')==='0'?'selected':'' ?>>Non Aktif</option>
                        </select>
                    </div>

                </div>
            </div>

        </div>

        <!-- FOOTER -->
        <div class="card-footer d-flex justify-content-between">
            <a href="<?= site_url('master/subject') ?>" class="btn btn-light px-4">
                <i class="fas fa-arrow-left me-1"></i> Kembali
            </a>

            <button class="btn btn-success px-4">
                <i class="fas fa-save me-1"></i> Simpan Data
            </button>
        </div>

    </form>
</div>

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