

<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="card">
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col-12">
                    <div class="d-flex justify-content-start flex-wrap gap-2 py-3">
                        <a href="<?php echo e(url('roles')); ?>" class="btn btn-primary">
                            <i class="fas fa-user-tag me-2"></i>Roles
                        </a>
                        <a href="<?php echo e(url('permissions')); ?>" class="btn btn-info">
                            <i class="fas fa-key me-2"></i>Permissions
                        </a>
                        <a href="<?php echo e(url('users')); ?>" class="btn btn-warning">
                            <i class="fas fa-users me-2"></i>Users
                        </a>
                    </div>
                </div>
            </div>
            <hr class="m-0">
        </div>

        <div class="card-body">
            <div class="row">
                <div class="col-12">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('status')): ?>
                        <div class="alert alert-success alert-dismissible fade show" role="alert">
                            <i class="fas fa-check-circle me-2"></i>
                            <?php echo e(session('status')); ?>

                            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                        </div>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                    <div class="card">
                        <div class="card-header d-flex justify-content-between align-items-center py-3">
                            <div>
                                <h5 class="card-title mb-0">
                                    <i class="fas fa-users me-2"></i>Users Management
                                </h5>
                                <p class="text-muted mb-0 small">Manage system users and their roles</p>
                            </div>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('create user')): ?>
                            <a href="<?php echo e(url('users/create')); ?>" class="btn btn-primary">
                                <i class="fas fa-plus me-2"></i>Add User
                            </a>
                            <?php endif; ?>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table id="users-table" class="table table-hover align-middle">
                                    <thead class="table-light">
                                        <tr>
                                            <th width="5%" class="text-center">ID</th>
                                            <th>Name</th>
                                            <th>Email</th>
                                            <th width="25%">Roles</th>
                                            <th width="15%" class="text-center">Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td class="text-center">
                                                <span class="badge bg-label-primary"><?php echo e($user->id); ?></span>
                                            </td>
                                            <td>
                                                <div class="d-flex align-items-center">
                                                    <div class="avatar avatar-sm me-3">
                                                        <span class="avatar-initial rounded-circle bg-primary">
                                                            <?php echo e(strtoupper(substr($user->name, 0, 1))); ?>

                                                        </span>
                                                    </div>
                                                    <div>
                                                        <h6 class="mb-0"><?php echo e($user->name); ?></h6>
                                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($user->created_at): ?>
                                                        <small class="text-muted">Joined <?php echo e($user->created_at->format('M d, Y')); ?></small>
                                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <a href="mailto:<?php echo e($user->email); ?>" class="text-decoration-none">
                                                    <i class="fas fa-envelope me-2 text-muted"></i>
                                                    <?php echo e($user->email); ?>

                                                </a>
                                            </td>
                                            <td>
                                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!empty($user->getRoleNames())): ?>
                                                    <div class="d-flex flex-wrap gap-1">
                                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $user->getRoleNames(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rolename): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <?php
                                                                $roleColors = [
                                                                    'admin' => 'danger',
                                                                    'manager' => 'warning',
                                                                    'editor' => 'info',
                                                                    'user' => 'success',
                                                                    'viewer' => 'secondary'
                                                                ];
                                                                $color = $roleColors[$rolename] ?? 'primary';
                                                            ?>
                                                            <span class="badge bg-<?php echo e($color); ?> px-2 py-1">
                                                                <i class="fas fa-user-tag me-1"></i>
                                                                <?php echo e(ucfirst($rolename)); ?>

                                                            </span>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                                    </div>
                                                <?php else: ?>
                                                    <span class="badge bg-label-secondary px-2 py-1">No roles assigned</span>
                                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                            </td>
                                            <td>
                                                <div class="d-flex justify-content-center gap-2">
                                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update user')): ?>
                                                    <a href="<?php echo e(url('users/'.$user->id.'/edit')); ?>" 
                                                       class="btn btn-sm btn-outline-primary" 
                                                       title="Edit User"
                                                       data-bs-toggle="tooltip">
                                                        <i class="fas fa-edit"></i>
                                                    </a>
                                                    <?php endif; ?>

                                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete user')): ?>
                                                    <form action="<?php echo e(url('users/'.$user->id.'/delete')); ?>" 
                                                          method="POST" 
                                                          class="d-inline">
                                                        <?php echo csrf_field(); ?>
                                                        <?php echo method_field('DELETE'); ?>
                                                        <button type="submit" 
                                                                class="btn btn-sm btn-outline-danger" 
                                                                title="Delete User"
                                                                data-bs-toggle="tooltip"
                                                                onclick="return confirm('Are you sure you want to delete <?php echo e($user->name); ?>?')">
                                                            <i class="fas fa-trash"></i>
                                                        </button>
                                                    </form>
                                                    <?php endif; ?>
                                                    
                                                   
                                                </div>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </tbody>
                                </table>
                            </div>
                            
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($users->isEmpty()): ?>
                            <div class="text-center py-5">
                                <div class="mb-3">
                                    <i class="fas fa-users fa-3x text-muted"></i>
                                </div>
                                <h5 class="text-muted">No Users Found</h5>
                                <p class="text-muted mb-0">Start by adding your first user to the system</p>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('create user')): ?>
                                <a href="<?php echo e(url('users/create')); ?>" class="btn btn-primary mt-3">
                                    <i class="fas fa-plus me-2"></i>Add First User
                                </a>
                                <?php endif; ?>
                            </div>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
    // Initialize DataTable
    $('#users-table').DataTable({
        responsive: true,
        pageLength: 10,
        lengthMenu: [5, 10, 25, 50, 100],
        order: [[0, 'desc']],
        columnDefs: [
            { 
                orderable: false, 
                targets: [3, 4] // disable sorting for Roles and Actions columns
            },
            {
                searchable: false,
                targets: [3, 4] // disable searching for Roles and Actions columns
            }
        ],
        language: {
            paginate: {
                previous: '<i class="fas fa-chevron-left"></i>',
                next: '<i class="fas fa-chevron-right"></i>'
            },
            search: "_INPUT_",
            searchPlaceholder: "Search users...",
            lengthMenu: "_MENU_ records per page",
            info: "Showing _START_ to _END_ of _TOTAL_ users"
        },
        initComplete: function() {
            // Add custom styling to DataTable elements
            $('.dataTables_length select').addClass('form-select form-select-sm');
            $('.dataTables_filter input').addClass('form-control form-control-sm');
            
            // Initialize Bootstrap tooltips
            var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
            var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
                return new bootstrap.Tooltip(tooltipTriggerEl);
            });
        }
    });
});
</script>

<style>
.avatar {
    width: 32px;
    height: 32px;
}

.avatar-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.badge {
    font-size: 0.85em;
    font-weight: 500;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.table > :not(caption) > * > * {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

.card-header {
    background-color: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.375rem 0.75rem;
    margin-left: 2px;
    border-radius: 0.375rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: white !important;
}
</style>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\xampp\htdocs\role_permission\resources\views/role-permission/user/index.blade.php ENDPATH**/ ?>