<?= $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>Daftar Confined Space Permit</b>
        <a href="<?= site_url('permit/confined/create') ?>" class="btn btn-light btn-sm">
            + Buat Permit
        </a>
    </div>

    <div class="card-body">
        <table id="dt_confined" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th>No</th>
                    <th>No Permit</th>
                    <th>Lokasi</th>
                    <th>Pemohon</th>
                    <th>Mulai</th>
                    <th>Status</th>
                    <th>Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
$(function () {
    $('#dt_confined').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: "<?= site_url('permit/confined/data') ?>",
            type: "POST"
        },
        columns: [
            { data: "id", render:(d,t,r,m)=>m.row+1 },
            { data: "permit_no" },
            { data: "lokasi_detail" },
            { data: "requester_name" },
            { data: "tanggal_mulai" },
            { data: "status", render: function(d){
                if(d==1) return '<span class="badge bg-success">Disetujui</span>';
                if(d==2) return '<span class="badge bg-danger">Ditolak</span>';
                if(d==3) return '<span class="badge bg-warning">Menunggu</span>';
                return '<span class="badge bg-secondary">Draft</span>';
            }},
            { data: "id", render: function(id){
                return `<a href="<?= site_url('permit/confined/view') ?>/${id}" class="btn btn-sm btn-info">Detail</a>`;
            }}
        ]
    });
});
</script>
<?= $this->endSection() ?>
