<?= $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 Mata Pelajaran</b>

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

    <div class="card-body">
        <table id="dt_subject" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th>No</th>
                    <th>Kode</th>
                    <th>Nama Mapel</th>
                    <th>Kelompok</th>
                    <th>Status</th>
                    <th width="140">Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
$(function () {
    $('#dt_subject').DataTable({
        processing: true,
        ajax: {
            url: "<?= site_url('master/subject/data') ?>",
            type: "GET"
        },
        columns: [
            { data: "id", render: (d,t,r,m) => m.row + 1 },
            { data: "kode_mapel" },
            { data: "nama_mapel" },
            { data: "kelompok" },
            {
                data: "is_active",
                render: function (v) {
                    return v == 1
                        ? '<span class="badge bg-success">Aktif</span>'
                        : '<span class="badge bg-secondary">Nonaktif</span>';
                }
            },
            {
                data: "id",
                render: function (id) {
                    return `
                    <div class="btn-group btn-group-sm">
                        <a href="<?= site_url('master/subject/edit') ?>/${id}"
                           class="btn btn-warning text-white">
                           <i class="fas fa-edit"></i>
                        </a>

                        <a href="<?= site_url('master/subject/delete') ?>/${id}"
                           onclick="return confirm('Yakin hapus mapel ini?')"
                           class="btn btn-danger">
                           <i class="fas fa-trash"></i>
                        </a>
                    </div>`;
                }
            }
        ]
    });
});
</script>
<?= $this->endSection() ?>
