<?php $__env->startSection('title', 'System Users'); ?>
<?php $__env->startSection('content'); ?>

<div class="container-fluid py-3">
    <div class="d-flex justify-content-end mb-2">
        <a href="<?php echo e(route('users.create')); ?>" class="btn btn-primary"> Add User</a>
    </div>

    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white py-3">
            <h5 class="mb-0"><i class="fas fa-users"></i> System Users</h5>
        </div>

        <div class="card-body">
            <?php if(session('success')): ?>
                <div class="alert alert-success"><?php echo e(session('success')); ?></div>
            <?php endif; ?>

            <?php if($errors->any()): ?>
                <div class="alert alert-danger">
                    <ul class="mb-0">
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li><?php echo e($error); ?></li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>
                </div>
            <?php endif; ?>

            <form id="salesAnalysisForm">
                <?php echo csrf_field(); ?>


            </form>
        </div>
    </div>
        <!-- Display Sales Analysis Data -->
        <div class="card shadow-sm mt-4">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover">
                <thead style="background-color: #0b7c85;" class="text-white">
                <tr>
                    <th style="width: 200px;">Name</th>
                    <th style="width: 190px;">Email</th>
                    <th style="width: 120px;">Phone</th>
                    <th style="width: 180px;">Role</th>
                    <th style="width: 180px;">Group</th>
                    <th style="width: 100px;">Status</th>
                    <th style="width: 180px;">Action</th>
                </tr>
                </thead>
                <tbody style="font-weight: bold;">
                    <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($user->name); ?></td>
                        <td><?php echo e($user->email); ?></td>
                        <td><?php echo e($user->phone ?? 'N/A'); ?></td>
                        <td>
                            <?php if($user->role): ?>
                                <?php echo e($user->role->name); ?>

                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($user->group): ?>
                                <?php echo e($user->group->name); ?>

                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($user->is_active ?? 1): ?>
                                <span class="badge bg-success text-white">Active</span>
                            <?php else: ?>
                                <span class="badge bg-danger">Inactive</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <!-- Edit Button -->
                            <a href="<?php echo e(route('users.edit', $user->id)); ?>" class="btn btn-sm btn-secondary">
                                 Edit
                            </a>
                            <!-- Delete Form -->
                            <?php if($user->email === 'admin@gmail.com'): ?>
                            <button class="btn btn-sm btn-danger" disabled title="Cannot delete admin user">Delete</button>
                            <!-- Disable delete button for admin user -->
                            <!-- Add a tooltip to explain why it's disabled -->

                            <?php else: ?>
                            <form action="<?php echo e(route('users.destroy', $user->id)); ?>" method="POST" style="display:inline-block;" onsubmit="return confirm('Are you sure you want to delete this user?');">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn btn-sm btn-danger">
                                    Delete
                                </button>
                            </form>
                            <?php endif; ?>
                            <a href="<?php echo e(route('user-permissions.addPermissions', $user->id)); ?>"
                            class="btn btn-sm btn-info"
                            title="Manage Permissions">
                          <i class="fas fa-user-shield"></i>
                            </a>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="7" class="text-center text-danger">No users found.</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
<style>
.btn-back {
    text-decoration: none;
    color: #1AB9D9;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    padding: 5px 15px;
    border-radius: 4px;
    transition: all 0.3s;
}
.btn-back:hover {
    background-color: rgba(26, 185, 217, 0.1);
    text-decoration: none;
}
.card {
    border-radius: 8px;
    overflow: hidden;
    border: none;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}
.card-header {
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding: 12px 20px;
}
.table th {
    background-color: #f8f9fa;
}
.table-responsive {
    overflow-x: auto;
}
.table-active {
    background-color: rgba(0,0,0,.05) !important;
}
.btn-process-all {
    background-color: #ffffff !important;
    color: #1AB9D9 !important;
    border: 1px solid rgba(26,185,217,0.35) !important;
    font-weight: 600 !important;
    padding: 7px 14px !important;
    box-shadow: none !important;
    line-height: 1 !important;
}
.btn-process-all:hover {
    background-color: #f5fbfc !important;
    color: #1498b0 !important;
    border-color: rgba(20,152,176,0.45) !important;
}

@media print {
    .btn-back, .card-header .btn, form {
        display: none !important;
    }
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    .table-responsive {
        overflow-x: visible;
    }
}
</style>
<?php $__env->stopSection(); ?>



<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/melsoftzimco/public_html/demo/resources/views/users/index.blade.php ENDPATH**/ ?>