<?php
/**
 * @var string $title
 * @var string $action
 * @var \CodeIgniter\Validation\ValidationInterface $validation
 * @var array $ta
 */
?>
<?= $this->extend('layout/default') ?>

<?= $this->section('content') ?>

<div class="card glass">
    <div class="card-header">
        <h5 class="m-0"><?= $title; ?></h5>
    </div>
    <div class="card-body">
        
        <form action="<?= $action ?>" method="post">
            <?= csrf_field() ?>
            
            <div class="form-group" style="margin-bottom: 15px;">
                <label for="kode_ta" style="display: block; margin-bottom: 5px; font-weight: 500;">Kode Tahun Akademik <span style="color: #ef4444;">*</span></label>
                <input type="text" class="form-control <?= ($validation->hasError('kode_ta')) ? 'is-invalid' : ''; ?>" id="kode_ta" name="kode_ta" value="<?= old('kode_ta', $ta['kode_ta'] ?? '') ?>" placeholder="Contoh: 20231" required autofocus style="width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px;">
                <small style="color: #6b7280; display: block; margin-top: 5px;">Format PDDIKTI: 5 digit angka (misal: 20231 untuk 2023/2024 Ganjil, 20232 untuk Genap)</small>
                <?php if($validation->hasError('kode_ta')) : ?>
                    <div style="color: #ef4444; font-size: 13px; margin-top: 5px;">
                        <?= $validation->getError('kode_ta'); ?>
                    </div>
                <?php endif; ?>
            </div>

            <div class="form-group" style="margin-bottom: 15px;">
                <label for="nama_ta" style="display: block; margin-bottom: 5px; font-weight: 500;">Nama Tahun Akademik <span style="color: #ef4444;">*</span></label>
                <input type="text" class="form-control <?= ($validation->hasError('nama_ta')) ? 'is-invalid' : ''; ?>" id="nama_ta" name="nama_ta" value="<?= old('nama_ta', $ta['nama_ta'] ?? '') ?>" placeholder="Contoh: 2023/2024 Ganjil" required style="width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px;">
                <?php if($validation->hasError('nama_ta')) : ?>
                    <div style="color: #ef4444; font-size: 13px; margin-top: 5px;">
                        <?= $validation->getError('nama_ta'); ?>
                    </div>
                <?php endif; ?>
            </div>

            <div class="form-group" style="margin-bottom: 20px;">
                <label for="status" style="display: block; margin-bottom: 5px; font-weight: 500;">Status</label>
                <div style="display: flex; align-items: center; gap: 10px; margin-top: 5px;">
                    <label style="display: flex; align-items: center; cursor: pointer; user-select: none;">
                        <input type="checkbox" name="status" id="status" value="Aktif" <?= old('status', $ta['status'] ?? 'Tidak Aktif') == 'Aktif' ? 'checked' : '' ?> style="width: 18px; height: 18px; cursor: pointer;">
                        <span style="margin-left: 8px;">Aktif</span>
                    </label>
                </div>
                <small style="color: #f59e0b; display: block; margin-top: 5px;">
                    <i class='bx bx-info-circle'></i> Mengaktifkan Tahun Akademik ini akan otomatis menonaktifkan Tahun Akademik yang lain.
                </small>
            </div>

            <div style="display: flex; gap: 10px;">
                <button type="submit" class="btn btn-primary" style="padding: 8px 16px;">
                    <i class='bx bx-save'></i> Simpan Data
                </button>
                <a href="<?= base_url('tahun-akademik') ?>" class="btn btn-secondary" style="padding: 8px 16px; text-decoration: none; border-radius: 6px;">
                    Batal
                </a>
            </div>
            
        </form>

    </div>
</div>

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