<?= $this->extend('backend/layout/main'); ?>
<?= $this->section('css'); ?>
<link rel="stylesheet" type="text/css" href="<?= base_url() ?>assets/backend/vendor/datatables/css/dataTables.bootstrap4.css">
<link rel="stylesheet" type="text/css" href="<?= base_url() ?>assets/backend/vendor/datatables/css/buttons.bootstrap4.css">
<?= $this->endSection(); ?>
<?= $this->section('title'); ?>Users<?= $this->endSection(); ?>
<?= $this->section('content'); ?>

<div class="container-fluid  dashboard-content">
    <div class="row">
        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
            <div class="page-header">
                <h2 class="pageheader-title">Users</h2>
                <div class="page-breadcrumb">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?= url_to('admin_home') ?>" class="breadcrumb-link">Dashboard</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Users</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
    </div>


    <div class="row">
        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
            <?= view_cell('AlertCell') ?>
            <div class="card">
                <div class="card-header d-flex">
                    <h5 class="mb-0">System Users</h5>
                    <div class="toolbar ml-auto">
                        <?php if (get_user()->role == 'Admin'): ?>
                            <a href="<?= url_to('create_user') ?>" class="btn btn-primary btn-sm ">+ Add User</a>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="example" class="table table-striped table-bordered second" style="width:100%">
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Role</th>
                                    <th>Email</th>
                                    <th>Status</th>
                                    <th>Created At</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($users as $user): ?>
                                    <tr>
                                        <td><a href="<?= url_to('user_profile', $user->id) ?>">
                                                <?= join(' ', [$user->first_name, $user->last_name]) ?>
                                            </a></td>
                                        <td><?= $user->role ?></td>
                                        <td><?= $user->email ?></td>
                                        <td><?= $user->status ?></td>
                                        <td><?= date('d M Y H:i', strtotime($user->created_at)) ?></td>
                                    </tr>
                                <?php endforeach; ?>

                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>Name</th>
                                    <th>Role</th>
                                    <th>Email</th>
                                    <th>Status</th>
                                    <th>Created At</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <!-- ============================================================== -->
        <!-- end data table  -->
        <!-- ============================================================== -->
    </div>

</div>

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

<?= $this->section('js'); ?>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/jquery.dataTables.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/dataTables.bootstrap4.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/dataTables.buttons.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/buttons.bootstrap4.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/data-table.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/jszip.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/pdfmake.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/vfs_fonts.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/buttons.html5.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/buttons.print.min.js"></script>
<script src="<?= base_url() ?>assets/backend/vendor/datatables/js/buttons.colVis.min.js"></script>
<?= $this->endSection(); ?>