<?php $__env->startSection('title', 'Create Custom Role'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="fw-bold mb-0">Create Custom Role</h5>
        <span class="text-muted fs-xs">Define Role Name & Select Granular Module Permissions</span>
    </div>
    <a href="<?php echo e(route('roles.index')); ?>" class="btn btn-sm btn-outline-secondary">
        <i class="bi bi-arrow-left me-1"></i> Back to Roles
    </a>
</div>

<form method="POST" action="<?php echo e(route('roles.store')); ?>">
    <?php echo csrf_field(); ?>

    <div class="card-erp p-3 mb-3">
        <div class="row g-3">
            <div class="col-md-6">
                <label class="form-label small fw-semibold">Role Name (e.g. Junior Cashier) <span class="text-danger">*</span></label>
                <input type="text" name="name" class="form-control form-control-sm" value="<?php echo e(old('name')); ?>" placeholder="e.g. Junior Cashier" required>
            </div>
            <div class="col-md-6">
                <label class="form-label small fw-semibold">Description</label>
                <input type="text" name="description" class="form-control form-control-sm" value="<?php echo e(old('description')); ?>" placeholder="e.g. Can create sales and print invoices only">
            </div>
        </div>
    </div>

    <!-- Granular Permission Matrix -->
    <div class="card-erp mb-3">
        <div class="card-erp-header bg-light">
            <span><i class="bi bi-grid-3x3-gap me-1 text-primary"></i> Module Permission Matrix</span>
            <button type="button" class="btn btn-xs btn-outline-secondary" onclick="toggleAllPermissions(true)">Select All</button>
        </div>
        <div class="p-3">
            <div class="row g-3">
                <?php $__currentLoopData = $permissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $module => $modPermissions): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="col-md-6 col-lg-4">
                        <div class="border rounded p-2 bg-white h-100 shadow-sm">
                            <div class="d-flex justify-content-between align-items-center border-bottom pb-1 mb-2">
                                <span class="fw-bold text-dark"><i class="bi bi-folder2-open me-1 text-primary"></i> <?php echo e($module); ?></span>
                                <input type="checkbox" class="form-check-input select-module" onclick="toggleModulePermissions(this, 'mod_<?php echo e(Str::slug($module)); ?>')">
                            </div>
                            <div class="mod_<?php echo e(Str::slug($module)); ?>">
                                <?php $__currentLoopData = $modPermissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $perm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div class="form-check">
                                        <input type="checkbox" name="permissions[]" value="<?php echo e($perm->id); ?>" class="form-check-input perm-checkbox" id="perm_<?php echo e($perm->id); ?>">
                                        <label class="form-check-label fs-xs" for="perm_<?php echo e($perm->id); ?>">
                                            <?php echo e($perm->name); ?>

                                        </label>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>
    </div>

    <div class="d-flex justify-content-end gap-2 mb-4">
        <a href="<?php echo e(route('roles.index')); ?>" class="btn btn-sm btn-secondary">Cancel</a>
        <button type="submit" class="btn btn-sm btn-primary">Create Role</button>
    </div>
</form>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    function toggleAllPermissions(checked) {
        document.querySelectorAll('.perm-checkbox').forEach(cb => cb.checked = checked);
    }
    function toggleModulePermissions(parent, modClass) {
        document.querySelectorAll('.' + modClass + ' .perm-checkbox').forEach(cb => cb.checked = parent.checked);
    }
</script>
<?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\saudi\resources\views\roles\create.blade.php ENDPATH**/ ?>