<?php include(APPPATH . 'views/layout/template-top.php'); ?>
<?php include(APPPATH . 'views/layout/header.php'); ?>
<!-- Main Container -->
<div class="main-container">
    <div class="xs-pd-20-10">
        <div class="min-height-200px">
            <!-- Page Header -->
            <div class="page-header mb-30">
                <div class="row">
                    <div class="col-md-6 col-sm-12">
                        <div class="title">
                            <h4>Users Management</h4>
                        </div>
                        <nav aria-label="breadcrumb" role="navigation">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>">Home</a></li>
                                <li class="breadcrumb-item active" aria-current="page">Users</li>
                            </ol>
                        </nav>
                    </div>
                    <div class="col-md-6 col-sm-12 text-right">
                        <a href="<?php echo base_url('users/add'); ?>" class="btn btn-primary">
                            <i class="fa fa-plus"></i> Add New User
                        </a>
                    </div>
                </div>
            </div>

            <!-- Users Table -->
            <div class="card-box mb-30">
                <div class="pd-20">
                    <h4 class="text-blue h4 mb-0">All Users</h4>
                </div>
                <div class="pb-20">
                    <div class="table-responsive">
                        <table class="table table-striped tbl-lms-user hover nowrap" id="usersDataTable" style="width:100%">
                            <thead>
                                <tr>
                                    <th>No.</th>
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th>Role</th>
                                    <th>Branch</th>
                                    <th>Status</th>
                                    <th class="datatable-nosort">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if (!empty($users)): ?>
                                    <?php $i=1; foreach ($users as $user): ?>
                                        <tr>
                                            <td><?php echo $i++; ?></td>
                                            <td><?php echo $user->name; ?></td>
                                            <td><?php echo $user->email; ?></td>
                                            <td><?php echo $user->role; ?></td>
                                            <td><?php echo $user->branch_name ? $user->branch_name : '-'; ?></td>
                                            <td>
                                                <?php if ($user->status == 'Active'): ?>
                                                    <span class="badge badge-success"><?php echo $user->status; ?></span>
                                                <?php else: ?>
                                                    <span class="badge badge-danger"><?php echo $user->status; ?></span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <a href="<?php echo base_url('users/edit/' . $user->admin_id); ?>" class="btn btn-sm btn-warning"><i class="fa fa-pencil"></i></a>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                <?php else: ?>
                                    <tr>
                                        <td colspan="6" class="text-center">No users found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <?php include(APPPATH . 'views/layout/footer.php'); ?>
    </div>
</div>
<?php include(APPPATH . 'views/layout/template-bottom.php'); ?>