<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <h5 class="mb-0 fw-bold">Activity Log</h5>
</div>

<div class="card">
    <div class="card-body p-0">
        <table id="logsTable" class="table table-hover align-middle mb-0 w-100">
            <thead class="table-light">
                <tr>
                    <th>Waktu</th>
                    <th>Username</th>
                    <th>Aksi</th>
                    <th>Deskripsi</th>
                    <th>IP</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script>
$('#logsTable').DataTable({
    processing: true, serverSide: true,
    ajax: {
        url: BASE_URL + 'logs/list', type: 'POST',
        data: function(d) { d[csrfToken()] = csrfHash(); }
    },
    order: [[0, 'desc']],
    pageLength: 25,
    columns: [
        { data: 'created_at', render: d => d ? d.replace('T',' ').slice(0,19) : '' },
        { data: 'username',   render: d => `<code>${d||''}</code>` },
        { data: 'action',     render: d => `<span class="badge bg-secondary">${d||''}</span>` },
        { data: 'description' },
        { data: 'ip_address', render: d => `<small class="text-muted">${d||''}</small>` },
    ],
    language: {
        processing: 'Memuat...', search: 'Cari:',
        lengthMenu: 'Tampilkan _MENU_ data',
        info: 'Menampilkan _START_–_END_ dari _TOTAL_ log',
        paginate: { first:'«', last:'»', previous:'‹', next:'›' }
    }
});
</script>
<?= $this->endSection() ?>
