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

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

    <div class="card-body">
        <table id="dt_kelas" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th width="50">No</th>
                    <th>Nama Kelas</th>
                    <th width="180">Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
    $(function () {
        $('#dt_kelas').DataTable({
            processing: true,
            serverSide: true,
            ajax: {
                url: "<?= site_url('master/kelas/data') ?>",
                type: "GET"
            },
            columns: [
                {
                    data: "id",
                    render: (d, t, r, m) => m.row + 1
                },
                { data: "nama_kelas" },
                {
                    data: "id",
                    orderable: false,
                    render: function (id) {
                        return `
                        <div class="btn-group">
<a href="<?= site_url('master/kelas/edit') ?>/${id}"
   class="btn btn-sm btn-warning text-white">Edit</a>

                            <a href="<?= site_url('master/kelas/delete') ?>/${id}"
                               onclick="return confirm('Yakin hapus kelas ini?')"
                               class="btn btn-sm btn-danger">Hapus</a>
                        </div>
                    `;
                    }
                }
            ]
        });
    });
</script>
<?= $this->endSection() ?>