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

<div class="card shadow-sm">
    <div class="card-header d-flex justify-content-between align-items-center bg-primary text-white">
        <b>Master Jurusan / Program</b>

        <a href="<?= site_url('master/major/create') ?>"
           class="btn btn-warning btn-sm text-dark fw-bold shadow-sm">
            <i class="fas fa-plus me-1"></i> Tambah Jurusan
        </a>
    </div>

    <div class="card-body">
        <table id="dt_major" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th width="50">No</th>
                    <th>Kode</th>
                    <th>Nama Jurusan</th>
                    <th>Level</th>
                    <th>Kuota</th>
                    <th>Status</th>
                    <th width="160">Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
$(function () {
    $('#dt_major').DataTable({
        processing: true,
        serverSide: false,
        ajax: {
            url: "<?= site_url('master/major/data') ?>",
            type: "GET"
        },
        columns: [
            {
                data: "id",
                render: (d, t, r, m) => m.row + 1
            },
            { data: "code" },
            { data: "name" },
            { data: "level" },
            { data: "quota" },
            {
                data: "is_active",
                render: d =>
                    d == 1
                        ? '<span class="badge bg-success">Aktif</span>'
                        : '<span class="badge bg-danger">Nonaktif</span>'
            },
            {
                data: "id",
                orderable: false,
                render: function (id) {
                    return `
                        <div class="btn-group">
                            <a href="<?= site_url('master/major/edit') ?>/${id}"
                               class="btn btn-sm btn-warning text-white">
                                Edit
                            </a>
                            <a href="<?= site_url('master/major/delete') ?>/${id}"
                               onclick="return confirm('Yakin hapus jurusan ini?')"
                               class="btn btn-sm btn-danger">
                                Hapus
                            </a>
                        </div>
                    `;
                }
            }
        ]
    });
});
</script>
<?= $this->endSection() ?>
