<div id="content">
    <div class="container-fluid">

        <!-- Page Heading -->
        <h1 class="h3 mb-2 text-gray-800">Users</h1>
        <!-- DataTales Example -->
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary" style="display: inline;">Latest Records</h6>
                <a href="javascript:void(0);" onclick="AddUserModal()"
                   class="d-sm-inline-block btn btn-sm btn-primary shadow-sm float-right">
                    <i class="fas fa-user fa-sm text-white-50 mr-1 "></i>Add User</a>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-bordered" id="UserRecords">
                        <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Full Name</th>
                            <th>Username</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Action</th>

                        </tr>
                        </thead>
                        <tbody>
                        <?php $cnt = 0;
                        foreach ($AllUsers as $records) {
                            $cnt++;
                            ?>
                            <tr>
                                <td><?= $cnt ?></td>
                                <td><?= ucwords($records['FullName']) ?></td>
                                <td><?= $records['Username'] ?></td>
                                <td><?= (isset($records['Type']) && $records['Type'] == 'admin' ? 'Admin' : 'User') ?></td>
                                <td>
                                    <badge class="badge badge-success"><?= ucwords($records['Status']) ?></badge>
                                </td>
                                <td>
                                    <a class="badge badge-primary" style="cursor: pointer;" href="javascript:void(0);"
                                       onclick="UpdateUserModal(<?= $records['UID'] ?>)">Update
                                    </a>
                                    <a class="badge badge-danger" style="cursor: pointer;" href="javascript:void(0);"
                                       onclick="DeleteUser(<?= $records['UID'] ?>)">Delete
                                    </a>
                                </td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

    </div>
</div>
<?php
echo view('users/add_user_modal');
echo view('users/update_user_modal');
?>
<script type="text/javascript">
    $(document).ready(function () {
        $('#UserRecords').DataTable();
    });

    function AddUserModal() {
        $('.add_user_modal_lg').modal('show')
    }

    function DeleteUser(id) {
        if (confirm('Are Your Sure to Delete This User...')) {
            var response = AjaxResponse('user/Delete_user_by_id', "UID=" + id);
            if (response.status == 'success') {
                location.reload();
            }
        }
    }

    function UpdateUserModal(id) {
        var response = AjaxRequest('user/get_user_by_id', "UID=" + id, 'update_user_data');
        $('.update_user_modal_lg').modal('show');
    }

</script>
