<?php $__env->startSection('title', 'Edit Role Matrix'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-5xl mx-auto space-y-6" x-data="{
    search: '',
    selectAll() {
        document.querySelectorAll('.permission-checkbox').forEach(cb => cb.checked = true);
    },
    clearAll() {
        document.querySelectorAll('.permission-checkbox').forEach(cb => cb.checked = false);
    },
    selectModule(moduleClass) {
        document.querySelectorAll('.' + moduleClass).forEach(cb => cb.checked = true);
    }
}">

    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Edit Role: <?php echo e($role->name); ?></h1>
            <p class="text-xs text-slate-500 dark:text-slate-400">Update data scope and permission capabilities for this role.</p>
        </div>
        <a href="<?php echo e(route('app.roles.index')); ?>" class="px-4 py-2 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-semibold text-xs rounded-xl">Back to Roles</a>
    </div>

    <form action="<?php echo e(route('app.roles.update', $role->id)); ?>" method="POST" class="space-y-6">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>

        <!-- Role Metadata Section -->
        <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4">
            <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Role Configuration</h3>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-xs">
                <div>
                    <label for="name" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Role Name *</label>
                    <input type="text" name="name" id="name" required value="<?php echo e($role->name); ?>" <?php echo e($role->is_system ? 'readonly' : ''); ?> 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>
                    <label for="data_scope" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Data Access Scope *</label>
                    <select name="data_scope" id="data_scope" required 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="own" <?php echo e($role->data_scope === 'own' ? 'selected' : ''); ?>>Own Records</option>
                        <option value="assigned" <?php echo e($role->data_scope === 'assigned' ? 'selected' : ''); ?>>Assigned Records</option>
                        <option value="counter" <?php echo e($role->data_scope === 'counter' ? 'selected' : ''); ?>>Counter Level</option>
                        <option value="department" <?php echo e($role->data_scope === 'department' ? 'selected' : ''); ?>>Department Level</option>
                        <option value="own_branch" <?php echo e($role->data_scope === 'own_branch' ? 'selected' : ''); ?>>Own Branch</option>
                        <option value="selected_branches" <?php echo e($role->data_scope === 'selected_branches' ? 'selected' : ''); ?>>Selected Branches</option>
                        <option value="all_branches" <?php echo e($role->data_scope === 'all_branches' ? 'selected' : ''); ?>>All Branches</option>
                        <option value="tenant" <?php echo e($role->data_scope === 'tenant' ? 'selected' : ''); ?>>Entire Tenant Organization</option>
                    </select>
                </div>
            </div>
        </div>

        <!-- Permission Matrix Grid -->
        <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4">
            <div class="flex flex-col md:flex-row md:items-center justify-between gap-4 pb-3 border-b border-slate-200 dark:border-slate-700">
                <div>
                    <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Granular Permission Matrix</h3>
                </div>

                <div class="flex items-center space-x-2 rtl:space-x-reverse text-xs">
                    <input type="text" x-model="search" placeholder="Search permissions..." class="px-3 py-1.5 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-xs">
                    <button type="button" @click="selectAll()" class="px-3 py-1.5 bg-sky-100 dark:bg-sky-950 text-sky-600 dark:text-sky-400 font-bold rounded-xl">Select All</button>
                    <button type="button" @click="clearAll()" class="px-3 py-1.5 bg-slate-100 dark:bg-slate-700 text-slate-600 dark:text-slate-300 font-semibold rounded-xl">Clear All</button>
                </div>
            </div>

            <div class="space-y-6 pt-2">
                <?php $__currentLoopData = $permissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $module => $modulePermissions): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="p-4 rounded-2xl bg-slate-50 dark:bg-slate-900/60 border border-slate-200 dark:border-slate-700/50 space-y-3"
                         x-show="!search || '<?php echo e(strtolower($module)); ?>'.includes(search.toLowerCase())">
                        <div class="flex items-center justify-between border-b border-slate-200 dark:border-slate-700/60 pb-2">
                            <h4 class="text-xs font-bold text-slate-900 dark:text-white uppercase tracking-wider flex items-center space-x-2 rtl:space-x-reverse">
                                <span class="w-2 h-2 rounded-full bg-sky-500"></span>
                                <span><?php echo e(ucfirst($module)); ?> Management</span>
                            </h4>
                            <button type="button" @click="selectModule('mod-<?php echo e($module); ?>')" class="text-[11px] font-semibold text-sky-600 dark:text-sky-400 hover:underline">
                                Select <?php echo e(ucfirst($module)); ?>

                            </button>
                        </div>

                        <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3">
                            <?php $__currentLoopData = $modulePermissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $perm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <label class="flex items-start space-x-2 rtl:space-x-reverse p-2 rounded-xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 cursor-pointer hover:border-sky-500 transition-colors">
                                    <input type="checkbox" name="permissions[]" value="<?php echo e($perm->id); ?>" <?php echo e(in_array($perm->id, $rolePermissions) ? 'checked' : ''); ?> class="permission-checkbox mod-<?php echo e($module); ?> w-4 h-4 text-sky-600 border-slate-300 rounded focus:ring-sky-500 mt-0.5">
                                    <div>
                                        <span class="text-xs font-semibold text-slate-800 dark:text-slate-200 block"><?php echo e($perm->name); ?></span>
                                        <span class="text-[10px] text-slate-400 font-mono"><?php echo e($perm->slug); ?></span>
                                    </div>
                                </label>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>

        <div class="flex justify-end space-x-3 rtl:space-x-reverse">
            <a href="<?php echo e(route('app.roles.index')); ?>" class="px-5 py-2.5 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-bold text-xs rounded-xl">Cancel</a>
            <button type="submit" class="px-6 py-2.5 bg-sky-600 hover:bg-sky-700 text-white font-bold text-xs rounded-xl shadow-lg shadow-sky-600/25">
                Update Role Matrix
            </button>
        </div>
    </form>
</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\roles\edit.blade.php ENDPATH**/ ?>