<div class="row align-items-center">    

    <div class="col-sm-6">
        <div class="float-right d-none d-md-block">
           <a class="btn btn-primary waves-effect waves-light" href="<?php echo base_url(); ?>users/manage_users/add/">
                <i class="mdi mdi-plus mr-2"></i> Add New
            </a> 
        </div>
    </div>
</div>
<?php
if ($this->session->flashdata('alert_success')) {
    ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_success'); ?>
</div>
<?php
}

if ($this->session->flashdata('alert_danger')) {
    ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_danger'); ?>
</div>
<?php
}

if ($this->session->flashdata('alert_warning')) {
    ?>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_warning'); ?>
</div>
<?php
}
?>

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <table id="dmstable" class="table table-striped table-bordered dt-responsive nowrap"
                    style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                    <thead>
                        <tr>
                            <th>USERNAME</th>
                            <th>EMAIL</th>
                            <th>MOBILE</th>
                            <th>CREATED ON</th>
                            <th>ACTION</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                        if(isset($records)){
                            foreach($records as $row){ ?>
                            <tr>
                                <td><?= $row->username ?></td>
                                <td><?= $row->email ?></td>
                                <td><?= $row->mobile; ?></td>
                                <td><?= date('d-m-Y',strtotime($row->created_at)) ?></td>
                                <td>
                                    <a href="<?= base_url('users/manage_users/edit/'.$row->id) ?>" class="btn-sm btn-info" ><i class="ti-pencil-alt"></i></a>
                                </td>
                            </tr>

                           <?php  }
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">


function delete_item(id) {
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then(isConfirmed => {
        if (isConfirmed.value) {
            $.ajax({
                url: "<?php echo base_url(); ?>users/manage_users/delete/" + id + "/",
                success: function(result) {
                    if (result) {
                        window.location('settings/region');
                    }
                }
            });

            if (isConfirmed.value) {
                Swal.fire(
                    'Deleted!',
                    'User has been deleted.',
                    'success'
                );              
            }
        }
    });
}
</script>