<?= $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>MENU MANAGEMENT</b>
        <a href="<?= site_url('setting/menus/create') ?>" class="btn btn-light btn-sm">
            + Tambah Menu
        </a>
    </div>

    <div class="card-body">
        <table id="dt_menus" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th>No</th>
                    <th>Title</th>
                    <th>URL</th>
                    <th>Icon</th>
                    <th>Parent</th>
                    <th>Status</th>
                    <th width="120">Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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


<?= $this->section('scripts') ?>
<script>
$(function () {

    $('#dt_menus').DataTable({
        processing: true,
        serverSide: false,
        ajax: {
            url: "<?= site_url('setting/menus/data') ?>",
            type: "GET"
        },
        columns: [
            { data: "id", render:(d,t,r,m)=>m.row+1 },

            { data: "title" },

            { data: "url", render:function(d){
                return d ? `<code>${d}</code>` : `<span class="text-muted">#</span>`;
            }},

            { data: "icon", render:function(d){
                if(!d) return `<span class="text-muted">none</span>`;
                return `<i class="${d}"></i> <small>${d}</small>`;
            }},

            { data: "parent_title", render:function(d){
                return d ? d : `<span class="text-muted">ROOT</span>`;
            }},

            { data: "is_active", render:function(d){
                if(d==1) return `<span class="badge bg-success">Active</span>`;
                return `<span class="badge bg-danger">Off</span>`;
            }},

            { data: "id", render:function(id){
                return `
                <a href="<?= site_url('setting/menus/edit') ?>/${id}" class="btn btn-sm btn-warning">Edit</a>
                <a href="<?= site_url('setting/menus/delete') ?>/${id}" class="btn btn-sm btn-danger"
                   onclick="return confirm('Hapus menu ini?')">Delete</a>`;
            }}
        ]
    });

});
</script>
<?= $this->endSection() ?>
