<?php $__env->startSection('title', 'User Accounts Management'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6">
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">ERP User Accounts</h1>
            <p class="text-xs text-slate-500 dark:text-slate-400">Manage login credentials, roles, branches, and permission overrides for staff.</p>
        </div>
        <a href="<?php echo e(route('app.users.create')); ?>" class="inline-flex items-center px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white font-semibold text-xs rounded-xl shadow-sm transition-all">
            + Create New User
        </a>
    </div>

    <!-- Search & Filters Bar (Requirement 13) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl p-4 border border-slate-200 dark:border-slate-700/60 shadow-sm">
        <form action="<?php echo e(route('app.users.index')); ?>" method="GET" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-5 gap-3 text-xs">
            <div>
                <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Search name, email, mobile, code..." class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
            </div>

            <div>
                <select name="role_id" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                    <option value="">All Roles</option>
                    <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($role->id); ?>" <?php echo e(request('role_id') == $role->id ? 'selected' : ''); ?>><?php echo e($role->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div>
                <select name="branch_id" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                    <option value="">All Branches</option>
                    <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($branch->id); ?>" <?php echo e(request('branch_id') == $branch->id ? 'selected' : ''); ?>><?php echo e($branch->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div>
                <select name="status" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                    <option value="">All Statuses</option>
                    <option value="active" <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>Active</option>
                    <option value="suspended" <?php echo e(request('status') == 'suspended' ? 'selected' : ''); ?>>Suspended</option>
                </select>
            </div>

            <div class="flex items-center space-x-2 rtl:space-x-reverse">
                <button type="submit" class="w-full py-2 bg-sky-600 text-white font-bold rounded-xl hover:bg-sky-700">Filter</button>
                <a href="<?php echo e(route('app.users.index')); ?>" class="py-2 px-3 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-semibold rounded-xl">Clear</a>
            </div>
        </form>
    </div>

    <!-- Users Table (Requirement 13) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left rtl:text-right text-xs">
                <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                    <tr>
                        <th class="px-6 py-4">User Details</th>
                        <th class="px-6 py-4">Role</th>
                        <th class="px-6 py-4">Branch</th>
                        <th class="px-6 py-4">Employee Link</th>
                        <th class="px-6 py-4">Last Login</th>
                        <th class="px-6 py-4">Status</th>
                        <th class="px-6 py-4 text-right rtl:text-left">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30 transition-colors">
                            <td class="px-6 py-4">
                                <div class="flex items-center space-x-3 rtl:space-x-reverse">
                                    <div class="w-9 h-9 rounded-xl bg-sky-600 text-white font-bold flex items-center justify-center text-xs uppercase shrink-0">
                                        <?php echo e(substr($user->name, 0, 2)); ?>

                                    </div>
                                    <div>
                                        <div class="font-bold text-slate-900 dark:text-white"><?php echo e($user->name); ?></div>
                                        <div class="text-[11px] text-slate-400 font-normal"><?php echo e($user->email); ?> • <?php echo e($user->username); ?></div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4">
                                <span class="px-2.5 py-1 rounded-lg bg-sky-100 dark:bg-sky-950/80 text-sky-700 dark:text-sky-300 font-bold text-[11px]">
                                    <?php echo e($user->getPrimaryRoleName()); ?>

                                </span>
                            </td>
                            <td class="px-6 py-4">
                                <span class="text-slate-700 dark:text-slate-300 font-medium">
                                    <?php echo e($user->defaultBranch ? $user->defaultBranch->name : 'Dubai Main Branch'); ?>

                                </span>
                            </td>
                            <td class="px-6 py-4">
                                <?php if($user->employee): ?>
                                    <span class="text-xs font-mono text-emerald-600 dark:text-emerald-400 font-bold"><?php echo e($user->employee->employee_code); ?></span>
                                <?php else: ?>
                                    <span class="text-slate-400 text-[11px]">Direct User Account</span>
                                <?php endif; ?>
                            </td>
                            <td class="px-6 py-4 text-slate-500 text-[11px]">
                                <?php echo e($user->last_login_at ? $user->last_login_at->diffForHumans() : 'Never'); ?>

                            </td>
                            <td class="px-6 py-4">
                                <?php if($user->status === 'active'): ?>
                                    <span class="px-2.5 py-0.5 rounded-full bg-emerald-100 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300 text-[10px] font-bold">Active</span>
                                <?php else: ?>
                                    <span class="px-2.5 py-0.5 rounded-full bg-rose-100 dark:bg-rose-950 text-rose-700 dark:text-rose-300 text-[10px] font-bold"><?php echo e(ucfirst($user->status)); ?></span>
                                <?php endif; ?>
                            </td>
                            <td class="px-6 py-4 text-right rtl:text-left space-x-2 rtl:space-x-reverse">
                                <a href="<?php echo e(route('app.users.edit', $user->id)); ?>" class="text-sky-600 hover:text-sky-800 font-bold">Edit</a>
                                <a href="<?php echo e(route('app.users.overrides', $user->id)); ?>" class="text-purple-600 hover:text-purple-800 font-bold">Overrides</a>
                                <a href="<?php echo e(route('app.users.login_history', $user->id)); ?>" class="text-slate-500 hover:text-slate-700 font-semibold">History</a>

                                <form action="<?php echo e(route('app.users.toggle_status', $user->id)); ?>" method="POST" class="inline">
                                    <?php echo csrf_field(); ?>
                                    <button type="submit" class="text-amber-600 hover:text-amber-800 font-semibold">
                                        <?php echo e($user->status === 'active' ? 'Suspend' : 'Activate'); ?>

                                    </button>
                                </form>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-200 dark:border-slate-700">
            <?php echo e($users->links()); ?>

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

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\typingcenter\resources\views\tenant\users\index.blade.php ENDPATH**/ ?>