<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\AppLayout::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <?php echo e(__('User Management')); ?>

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

    <div class="p-6 space-y-6">
        <?php if(session('status')): ?>
            <div class="rounded-md bg-green-50 border border-green-200 px-4 py-3 text-sm text-green-800">
                <?php echo e(session('status')); ?>

            </div>
        <?php endif; ?>

        <?php if($errors->any()): ?>
            <div class="rounded-md bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-800">
                <ul class="list-disc pl-5 space-y-1">
                    <?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; ?>

        <div class="bg-white border border-gray-200 rounded-xl shadow-sm p-5 flex items-center justify-between">
            <div>
                <h1 class="text-xl font-semibold text-gray-900">Users</h1>
                <p class="mt-1 text-sm text-gray-600">
                    Manage users for this dealer context. Roles and departments are dealer-scoped.
                </p>
            </div>

            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('settings.users.manage')): ?>
                <a
                    href="<?php echo e(route('settings.users.create')); ?>"
                    class="inline-flex items-center rounded-lg bg-red-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700"
                >
                    Add User
                </a>
            <?php endif; ?>
        </div>

        <div class="bg-white border border-gray-200 rounded-xl shadow-sm p-4 space-y-4">
            <form method="GET" action="<?php echo e(route('settings.users.index')); ?>" class="flex flex-wrap items-end gap-3">
                <div class="w-full sm:w-64">
                    <label for="q" class="block text-xs font-medium text-gray-600">Search</label>
                    <input
                        id="q"
                        name="q"
                        type="text"
                        value="<?php echo e(request('q')); ?>"
                        class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-red-500 focus:ring-red-500 text-sm"
                        placeholder="Name, surname, email"
                    >
                </div>

                <div>
                    <label for="status" class="block text-xs font-medium text-gray-600">Status</label>
                    <select
                        id="status"
                        name="status"
                        class="mt-1 block w-40 rounded-md border-gray-300 shadow-sm focus:border-red-500 focus:ring-red-500 text-sm"
                    >
                        <option value="">All</option>
                        <option value="active" <?php if(request('status') === 'active'): echo 'selected'; endif; ?>>Active</option>
                        <option value="disabled" <?php if(request('status') === 'disabled'): echo 'selected'; endif; ?>>Disabled</option>
                    </select>
                </div>

                <div class="flex-1"></div>

                <div>
                    <button
                        type="submit"
                        class="inline-flex items-center rounded-md bg-gray-900 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-800"
                    >
                        Filter
                    </button>
                </div>
            </form>
        </div>

        <div class="bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden">
            <table class="min-w-full divide-y divide-gray-200 text-sm">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Name</th>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Email</th>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Department</th>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Roles</th>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Status</th>
                        <th class="px-4 py-2 text-left font-semibold text-gray-700">Created</th>
                        <th class="px-4 py-2 text-center font-semibold text-gray-700">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td class="px-4 py-2 text-gray-900">
                                <?php echo e($user->full_name); ?>

                            </td>
                            <td class="px-4 py-2 text-gray-700">
                                <?php echo e($user->email); ?>

                                <?php if($user->is_builtin): ?>
                                    <span class="ml-1 inline-flex items-center rounded-full bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-700 align-middle">
                                        Built-in
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-2 text-gray-700">
                                <?php echo e(optional($user->department)->name ?? '—'); ?>

                            </td>
                            <td class="px-4 py-2 text-gray-700">
                                <?php echo e($user->roles->pluck('name')->join(', ') ?: '—'); ?>

                            </td>
                            <td class="px-4 py-2">
                                <?php if($user->is_disabled): ?>
                                    <span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-700">
                                        Disabled
                                    </span>
                                <?php else: ?>
                                    <span class="inline-flex items-center rounded-full bg-green-50 px-2 py-0.5 text-xs font-medium text-green-700">
                                        Active
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-2 text-gray-500">
                                <?php echo e($user->created_at?->format('Y-m-d') ?? '—'); ?>

                            </td>
                            <td class="px-4 py-2">
                                <div class="flex items-center justify-end gap-2">
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('settings.users.manage')): ?>
                                        <a
                                            href="<?php echo e(route('settings.users.edit', $user->id)); ?>"
                                            class="inline-flex items-center rounded-md border border-gray-200 px-2 py-1 text-xs text-gray-700 hover:bg-gray-50"
                                        >
                                            Edit
                                        </a>
                                    <?php endif; ?>

                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('settings.users.security')): ?>
                                        <?php if(auth()->id() !== $user->id): ?>
                                            <form
                                                id="user-toggle-<?php echo e($user->id); ?>"
                                                method="POST"
                                                action="<?php echo e(route('settings.users.toggle-disabled', $user->id)); ?>"
                                            >
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('PATCH'); ?>
                                                <button
                                                    type="button"
                                                    @click="$store.__confirm.openConfirm('Are you sure you want to change this user\'s status?', 'user-toggle-<?php echo e($user->id); ?>')"
                                                    class="inline-flex items-center rounded-md border border-gray-200 px-2 py-1 text-xs text-gray-700 hover:bg-gray-50"
                                                >
                                                    <?php echo e($user->is_disabled ? 'Enable' : 'Disable'); ?>

                                                </button>
                                            </form>

                                            <form
                                                id="user-reset-<?php echo e($user->id); ?>"
                                                method="POST"
                                                action="<?php echo e(route('settings.users.reset-password', $user->id)); ?>"
                                            >
                                                <?php echo csrf_field(); ?>
                                                <button
                                                    type="button"
                                                    @click="$store.__confirm.openConfirm('Reset password and force change on next login?', 'user-reset-<?php echo e($user->id); ?>')"
                                                    class="inline-flex items-center rounded-md border border-gray-200 px-2 py-1 text-xs text-gray-700 hover:bg-gray-50"
                                                >
                                                    Reset Password
                                                </button>
                                            </form>

                                            <?php if(! $user->is_builtin): ?>
                                                <form
                                                    id="user-delete-<?php echo e($user->id); ?>"
                                                    method="POST"
                                                    action="<?php echo e(route('settings.users.destroy', $user->id)); ?>"
                                                >
                                                    <?php echo csrf_field(); ?>
                                                    <?php echo method_field('DELETE'); ?>
                                                    <button
                                                        type="button"
                                                        @click="$store.__confirm.openConfirm('Are you sure you want to delete this user?', 'user-delete-<?php echo e($user->id); ?>')"
                                                        class="inline-flex items-center rounded-md border border-red-200 px-2 py-1 text-xs text-red-700 hover:bg-red-50"
                                                    >
                                                        Delete
                                                    </button>
                                                </form>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="7" class="px-4 py-4 text-center text-sm text-gray-500">
                                No users found.
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>

            <div class="px-4 py-3 border-t border-gray-100">
                <?php echo e($users->links()); ?>

            </div>
        </div>

        <?php if($deletedUsers->isNotEmpty()): ?>
            <div class="bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden">
                <div class="px-4 py-3 border-b border-gray-100 flex items-center justify-between">
                    <div>
                        <h2 class="text-sm font-semibold text-gray-900">Deleted Users</h2>
                        <p class="mt-1 text-xs text-gray-500">
                            These users have been soft deleted and are not able to log in.
                        </p>
                    </div>
                </div>

                <table class="min-w-full divide-y divide-gray-200 text-sm">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-4 py-2 text-left font-semibold text-gray-700">Name</th>
                            <th class="px-4 py-2 text-left font-semibold text-gray-700">Email</th>
                            <th class="px-4 py-2 text-left font-semibold text-gray-700">Department</th>
                            <th class="px-4 py-2 text-left font-semibold text-gray-700">Roles</th>
                            <th class="px-4 py-2 text-left font-semibold text-gray-700">Deleted At</th>
                            <th class="px-4 py-2 text-center font-semibold text-gray-700">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100">
                        <?php $__currentLoopData = $deletedUsers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="px-4 py-2 text-gray-900">
                                    <?php echo e($user->full_name); ?>

                                </td>
                                <td class="px-4 py-2 text-gray-700">
                                    <?php echo e($user->email); ?>

                                </td>
                                <td class="px-4 py-2 text-gray-700">
                                    <?php echo e(optional($user->department)->name ?? '—'); ?>

                                </td>
                                <td class="px-4 py-2 text-gray-700">
                                    <?php echo e($user->roles->pluck('name')->join(', ') ?: '—'); ?>

                                </td>
                                <td class="px-4 py-2 text-gray-500">
                                    <?php echo e($user->deleted_at?->format('Y-m-d H:i') ?? '—'); ?>

                                </td>
                                <td class="px-4 py-2">
                                    <div class="flex items-center justify-center">
                                        <form
                                            method="POST"
                                            action="<?php echo e(route('settings.users.restore', $user->id)); ?>"
                                        >
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('PATCH'); ?>
                                            <button
                                                type="submit"
                                                class="inline-flex items-center rounded-md border border-gray-200 px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50"
                                            >
                                                Restore
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>

<?php /**PATH C:\Projects\mtt-os\resources\views\settings\users\index.blade.php ENDPATH**/ ?>