<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><i class="fas fa-user-shield me-2"></i><?= lang('admin.users') ?></h4>
    <?php if (Gate::can('users.manage')): ?>
    <a href="/admin/users/create" class="btn btn-primary"><i class="fas fa-plus me-1"></i>Create User</a>
    <?php endif; ?>
</div>
<div class="card">
    <div class="card-body">
        <table id="users-table" class="table table-striped table-hover w-100"
               data-url="/admin/users/datatable"
               data-columns='[{"data":"id"},{"data":"username"},{"data":"full_name"},{"data":"email"},{"data":"roles"},{"data":"status"},{"data":"last_login"},{"data":"actions","orderable":false,"searchable":false}]'>
            <thead>
                <tr>
                    <th>#</th><th>Username</th><th>Name</th><th>Email</th><th>Roles</th><th>Status</th><th>Last Login</th><th>Actions</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<?php $__view->push('scripts') ?>
<script>
$(function(){
    const dt = DataTableHelper.init('users-table', {order:[[0,'desc']]});
    $(document).on('click','.btn-unlock',function(){
        const id = $(this).data('id');
        if(!confirm('Unlock this user?')) return;
        $.post('/admin/users/'+id+'/unlock', {_token:'<?= csrf_token() ?>'}, function(r){
            if(r.success) { FormHelper.showToast('success',r.message); DataTableHelper.reload('users-table'); }
            else FormHelper.showToast('error',r.message);
        },'json');
    });
});
</script>
<?php $__view->endPush() ?>