<?php $__env->startSection('title', $user->exists ? 'Editar utilizador' : 'Novo utilizador'); ?>
<?php $__env->startSection('content'); ?>
    <div class="page-heading"><div><span class="eyebrow">ADMINISTRAÇÃO · UTILIZADORES</span><h1><?php echo e($user->exists ? 'Editar '.$user->name : 'Criar utilizador'); ?></h1><p>O acesso efectivo resulta da combinação entre unidade, departamento e perfis.</p></div><a class="secondary-link" href="<?php echo e(route('admin.users.index')); ?>">← Voltar</a></div>
    <?php if($errors->any()): ?><div class="alert danger"><?php echo e($errors->first()); ?></div><?php endif; ?>
    <form class="panel management-form" method="POST" action="<?php echo e($user->exists ? route('admin.users.update', $user) : route('admin.users.store')); ?>"><?php echo csrf_field(); ?> <?php if($user->exists): ?><?php echo method_field('PUT'); ?><?php endif; ?>
        <div class="form-section"><div><span class="eyebrow">IDENTIDADE</span><h2>Conta institucional</h2><p>Dados utilizados para identificar o colaborador.</p></div><div class="form-grid">
            <label class="field span-2"><span>Nome completo</span><input name="name" value="<?php echo e(old('name', $user->name)); ?>" required></label><label class="field"><span>Nome de utilizador</span><input name="username" value="<?php echo e(old('username', $user->username)); ?>" required placeholder="nome.apelido"></label><label class="field"><span>Email</span><input type="email" name="email" value="<?php echo e(old('email', $user->email)); ?>" required></label>
            <label class="field"><span><?php echo e($user->exists ? 'Nova palavra-passe (opcional)' : 'Palavra-passe temporária'); ?></span><input type="password" name="password" <?php echo e($user->exists ? '' : 'required'); ?> autocomplete="new-password"></label><label class="field"><span>Confirmar palavra-passe</span><input type="password" name="password_confirmation" <?php echo e($user->exists ? '' : 'required'); ?> autocomplete="new-password"></label>
        </div></div>
        <div class="form-section"><div><span class="eyebrow">AFECTAÇÃO</span><h2>Contexto de trabalho</h2><p>“Todas as filiais” concede acesso global conforme as permissões.</p></div><div class="form-grid">
            <label class="field"><span>Organização</span><select name="organization_id" required><?php $__currentLoopData = $organizations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $organization): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($organization->id); ?>" <?php if(old('organization_id', $assignment?->organization_id ?: $organizations->first()?->id) == $organization->id): echo 'selected'; endif; ?>><?php echo e($organization->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></label>
            <label class="field"><span>Filial</span><select name="branch_id"><option value="">Todas as filiais / acesso global</option><?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($branch->id); ?>" <?php if(old('branch_id', $assignment?->branch_id) == $branch->id): echo 'selected'; endif; ?>><?php echo e($branch->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></label>
            <label class="field span-2"><span>Departamento/unidade</span><select name="department_id"><option value="">Sem departamento específico</option><?php $__currentLoopData = $departments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $department): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($department->id); ?>" <?php if(old('department_id', $assignment?->department_id) == $department->id): echo 'selected'; endif; ?>><?php echo e($department->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></label>
        </div></div>
        <div class="form-section"><div><span class="eyebrow">AUTORIZAÇÃO</span><h2>Perfis atribuídos</h2><p>Pode combinar um perfil operacional com um administrativo.</p></div><div class="choice-grid"><?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><label class="choice-card"><input type="checkbox" name="role_ids[]" value="<?php echo e($role->id); ?>" <?php if(in_array($role->id, old('role_ids', $selectedRoleIds))): echo 'checked'; endif; ?>><span class="role-mark <?php echo e($role->is_privileged ? 'privileged' : ''); ?>"><?php echo e($role->is_privileged ? '◆' : '◇'); ?></span><div><strong><?php echo e($role->name); ?></strong><small><?php echo e($role->is_privileged ? 'Disponível no Modo de Administração' : 'Perfil operacional'); ?></small></div></label><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></div></div>
        <div class="form-options"><label><input type="checkbox" name="is_active" value="1" <?php if(old('is_active', $user->exists ? $user->is_active : true)): echo 'checked'; endif; ?>> Conta activa</label><span>A reposição da palavra-passe obrigará nova alteração no próximo acesso.</span></div><div class="form-actions"><a class="secondary-link" href="<?php echo e(route('admin.users.index')); ?>">Cancelar</a><button class="primary-button compact" type="submit">Guardar utilizador</button></div>
    </form>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Joe B\.codex\.chatgpt-projects\g-p-6a6ce038586481919be04257dc687fef\nestab-ops\resources\views/admin/users/form.blade.php ENDPATH**/ ?>