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

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


    <div class="card-body">
        <table id="dt_employee" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th>No</th>
                    <th>NIK / Employee No</th>
                    <th>Nama</th>
                    <th>Jabatan</th>
                    <th>Departemen</th>
                    <th>Perusahaan</th>
                    <th>Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
    $(function () {
        $('#dt_employee').DataTable({
            ajax: {
                url: "<?= site_url('master/employees/data') ?>",
                type: "GET"
            },

            columns: [
                { data: "id", render: (d, t, r, m) => m.row + 1 },
                { data: "employee_no" },
                { data: "employee_name" },
                { data: "position" },
                { data: "department" },
                { data: "company" },
                {
                    data: "id",
                    render: function (id) {
                        return `
                        <div class="btn-group">
                            <a href="<?= site_url('master/employees/view') ?>/${id}" 
                               class="btn btn-sm btn-info">View</a>

                            <a href="<?= site_url('master/employees/edit') ?>/${id}" 
                               class="btn btn-sm btn-warning text-white">Edit</a>

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