

<?php $__env->startSection('title', 'Client Admin Permissions'); ?>
<?php $__env->startSection('page-title', 'Client Admin Permissions'); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-lg-8">
        <div class="table-container">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <h5 class="mb-1">Permissions for: <?php echo e($clientAdmin->name); ?></h5>
                    <p class="text-muted mb-0">Override default role permissions for this client admin</p>
                </div>
                <span class="badge bg-<?php echo e($clientAdmin->role === 'owner' ? 'primary' : 'info'); ?>">
                    <i class="bi bi-<?php echo e($clientAdmin->role === 'owner' ? 'star-fill' : 'person-badge'); ?> me-1"></i>
                    <?php echo e(ucfirst($clientAdmin->role)); ?>

                </span>
            </div>

            <div class="alert" style="background: linear-gradient(135deg, rgba(23, 162, 184, 0.1) 0%, rgba(0, 210, 255, 0.1) 100%); border: 1px solid rgba(23, 162, 184, 0.3);">
                <i class="bi bi-info-circle me-2"></i>
                <strong>How Permissions Work:</strong>
                <ul class="mb-0 mt-2 small">
                    <li><span class="badge bg-success">Role Default</span> - Permission granted by the <?php echo e(ucfirst($clientAdmin->role)); ?> role</li>
                    <li><span class="badge bg-primary">Override: Allow</span> - Explicitly grant permission to this admin</li>
                    <li><span class="badge bg-danger">Override: Deny</span> - Explicitly deny permission to this admin</li>
                </ul>
            </div>

            <form action="<?php echo e(route('dashboard.clients.admin-permissions.update', [$client->id, $clientAdmin->id])); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>

                <?php
                    $groupIcons = [
                        'client_users' => 'people',
                        'client_templates' => 'file-text',
                        'client_reports' => 'journal-text',
                        'client_admins' => 'person-gear',
                        'client_profile' => 'person-circle',
                        'client_dashboard' => 'grid-1x2',
                    ];
                    $groupLabels = [
                        'client_users' => 'User Management',
                        'client_templates' => 'Template Management',
                        'client_reports' => 'Reports',
                        'client_admins' => 'Admin Management',
                        'client_profile' => 'Profile',
                        'client_dashboard' => 'Dashboard',
                    ];
                ?>

                <?php $__currentLoopData = $allPermissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group => $permissions): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="card mb-4">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">
                            <i class="bi bi-<?php echo e($groupIcons[$group] ?? 'key'); ?> me-2"></i>
                            <?php echo e($groupLabels[$group] ?? ucfirst(str_replace('_', ' ', $group))); ?> Permissions
                        </h6>
                    </div>
                    <div class="card-body">
                        <?php $__currentLoopData = $permissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $permission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $hasRolePermission = $rolePermissions[$permission->permission_key] ?? false;
                            $override = $clientAdmin->permissionOverrides->where('permission_key', $permission->permission_key)->first();
                            $currentValue = $override ? ($override->is_allowed ? 'allow' : 'deny') : 'default';
                        ?>
                        <div class="row align-items-center py-2 border-bottom">
                            <div class="col-md-5">
                                <div class="fw-semibold"><?php echo e($permission->name); ?></div>
                                <small class="text-muted"><?php echo e($permission->description); ?></small>
                            </div>
                            <div class="col-md-3 text-center">
                                <?php if($hasRolePermission): ?>
                                    <span class="badge bg-success">Role Default: Allowed</span>
                                <?php else: ?>
                                    <span class="badge bg-secondary">Role Default: Denied</span>
                                <?php endif; ?>
                            </div>
                            <div class="col-md-4">
                                <select class="form-select form-select-sm" name="permissions[<?php echo e($permission->permission_key); ?>]">
                                    <option value="" <?php echo e($currentValue === 'default' ? 'selected' : ''); ?>>
                                        Use Role Default
                                    </option>
                                    <option value="1" <?php echo e($currentValue === 'allow' ? 'selected' : ''); ?>>
                                        Override: Allow
                                    </option>
                                    <option value="0" <?php echo e($currentValue === 'deny' ? 'selected' : ''); ?>>
                                        Override: Deny
                                    </option>
                                </select>
                            </div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                <div class="d-flex gap-3">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-lg me-2"></i>Save Permissions
                    </button>
                    <a href="<?php echo e(route('dashboard.clients.show', $client->id)); ?>" class="btn btn-outline-secondary">
                        Cancel
                    </a>
                </div>
            </form>
        </div>
    </div>

    <div class="col-lg-4">
        <!-- Client Admin Info Card -->
        <div class="table-container mb-4">
            <h6 class="mb-3">Client Admin Information</h6>
            <dl class="row mb-0">
                <dt class="col-sm-5">Name</dt>
                <dd class="col-sm-7"><?php echo e($clientAdmin->name); ?></dd>
                
                <dt class="col-sm-5">Email</dt>
                <dd class="col-sm-7"><?php echo e($clientAdmin->email); ?></dd>
                
                <dt class="col-sm-5">Role</dt>
                <dd class="col-sm-7">
                    <span class="badge bg-<?php echo e($clientAdmin->role === 'owner' ? 'primary' : 'info'); ?>">
                        <?php echo e(ucfirst($clientAdmin->role)); ?>

                    </span>
                </dd>
                
                <dt class="col-sm-5">Status</dt>
                <dd class="col-sm-7">
                    <?php if($clientAdmin->is_active): ?>
                        <span class="badge bg-success">Active</span>
                    <?php else: ?>
                        <span class="badge bg-secondary">Inactive</span>
                    <?php endif; ?>
                </dd>
                
                <dt class="col-sm-5">Organization</dt>
                <dd class="col-sm-7"><?php echo e($client->name); ?></dd>
            </dl>
        </div>

        <!-- Quick Actions -->
        <div class="table-container">
            <h6 class="mb-3">Quick Actions</h6>
            <div class="d-grid gap-2">
                <a href="<?php echo e(route('dashboard.clients.show', $client->id)); ?>" class="btn btn-outline-primary">
                    <i class="bi bi-building me-2"></i>View Organization
                </a>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp82\htdocs\AutoPromix\backend\resources\views\dashboard\client-admin-permissions.blade.php ENDPATH**/ ?>