<?php $__env->startSection('title', 'Modifica Utente'); ?>
<?php $__env->startSection('page_title', 'Modifica Utente: ' . $user->name); ?>

<?php $__env->startSection('breadcrumbs'); ?>
    <li class="breadcrumb-item"><a href="/admin/utenti">Admin</a></li>
    <li class="breadcrumb-item"><a href="/admin/utenti">Utenti</a></li>
    <li class="breadcrumb-item active"><?php echo e($user->name); ?></li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Dati Utente</h3>
            </div>
            <div class="card-body">
                <form method="POST" action="/admin/utenti/<?php echo e($user->id); ?>">
                    <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                    <div class="form-group">
                        <label>Nome *</label>
                        <input type="text" name="name" class="form-control" required value="<?php echo e(old('name', $user->name)); ?>">
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" class="form-control" required value="<?php echo e(old('email', $user->email)); ?>">
                    </div>
                    <div class="form-group">
                        <label>Nuova Password <small>(lascia vuoto per non cambiare)</small></label>
                        <input type="password" name="password" class="form-control" minlength="8">
                    </div>
                    <div class="form-group">
                        <label>Conferma Password</label>
                        <input type="password" name="password_confirmation" class="form-control" minlength="8">
                    </div>
                    <div class="form-group">
                        <label>Stato</label>
                        <select name="status" class="form-control" required>
                            <option value="active" <?php echo e(old('status', $user->status) === 'active' ? 'selected' : ''); ?>>Attivo</option>
                            <option value="suspended" <?php echo e(old('status', $user->status) === 'suspended' ? 'selected' : ''); ?>>Sospeso</option>
                            <option value="pending" <?php echo e(old('status', $user->status) === 'pending' ? 'selected' : ''); ?>>In attesa</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Ruolo Predefinito</label>
                        <select name="role_preset_id" class="form-control" id="rolePresetSelect">
                            <option value="">Personalizzato</option>
                            <?php $__currentLoopData = $rolePresets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $preset): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($preset->id); ?>" <?php echo e(old('role_preset_id', $user->role_preset_id) == $preset->id ? 'selected' : ''); ?>>
                                    <?php echo e($preset->name); ?> - <?php echo e($preset->description); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <input type="hidden" name="is_admin" value="0">
                    <div class="form-group">
                        <div class="custom-control custom-switch">
                            <input type="checkbox" class="custom-control-input" id="isAdmin" name="is_admin" value="1" <?php echo e(old('is_admin', $user->isSuperAdmin() ? '1' : '0') === '1' ? 'checked' : ''); ?>>
                            <label class="custom-control-label" for="isAdmin">Superadmin (bypass ACL)</label>
                        </div>
                    </div>

                    <div id="permissionsSection" class="mt-4">
                        <h5>Permessi Granulari</h5>
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>Modulo</th>
                                    <th>Nessuno</th>
                                    <th>Lettura</th>
                                    <th>Completo</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = \App\Models\User::MODULES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $module): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><strong><?php echo e(ucfirst($module)); ?></strong></td>
                                    <td><input type="radio" name="permissions[<?php echo e($module); ?>]" value="0" <?php echo e(($user->permissions[$module] ?? 0) == 0 ? 'checked' : ''); ?>></td>
                                    <td><input type="radio" name="permissions[<?php echo e($module); ?>]" value="1" <?php echo e(($user->permissions[$module] ?? 0) == 1 ? 'checked' : ''); ?>></td>
                                    <td><input type="radio" name="permissions[<?php echo e($module); ?>]" value="2" <?php echo e(($user->permissions[$module] ?? 0) == 2 ? 'checked' : ''); ?>></td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>

                    <div class="mt-4">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> Salva
                        </button>
                        <a href="/admin/utenti" class="btn btn-secondary">Annulla</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
$('#rolePresetSelect').change(function() {
    if ($(this).val()) {
        $('#permissionsSection').hide();
    } else {
        $('#permissionsSection').show();
    }
}).trigger('change');
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/glastree/resources/views/admin/utenti/edit.blade.php ENDPATH**/ ?>