<?php $__env->startSection('title', __('Editar usuario')); ?>

<?php $__env->startPush('head'); ?>
    <style>
        .rt-edit-password-wrap {
            position: relative;
        }
        .rt-edit-password-wrap .form-control {
            padding-right: 2.75rem;
        }
        .rt-password-toggle-btn {
            position: absolute;
            right: 0.6rem;
            top: 50%;
            transform: translateY(-50%);
            background: transparent;
            border: none;
            color: #8e8e93;
            cursor: pointer;
            z-index: 5;
            padding: 0.35rem 0.5rem;
            line-height: 1;
            border-radius: 8px;
            transition: color 0.2s, background-color 0.2s;
        }
        .rt-password-toggle-btn:hover {
            color: var(--rt-cherry, #b91830);
            background-color: rgba(0, 0, 0, 0.04);
        }
        .rt-password-toggle-btn:focus {
            outline: none;
            box-shadow: 0 0 0 2px rgba(185, 24, 48, 0.25);
        }
    </style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="container-fluid px-0">
        <div class="mb-4">
            <a href="<?php echo e(route('dashboard.users.index')); ?>" class="small text-muted text-decoration-none">
                <i class="bi bi-arrow-left" aria-hidden="true"></i> <?php echo e(__('Volver al listado')); ?>

            </a>
            <h1 class="h3 mt-2 mb-1 text-dark font-weight-bold"><?php echo e(__('Editar usuario')); ?></h1>
            <p class="text-muted mb-0 small"><?php echo e(__(':name — :email', ['name' => $editedUser->name, 'email' => $editedUser->email])); ?></p>
        </div>

        <div class="card shadow-sm border-0" style="border-radius: 16px;">
            <div class="card-body p-4">
                <form method="post" action="<?php echo e(route('dashboard.users.update', $editedUser)); ?>">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PUT'); ?>

                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label class="rt-label" for="edit-name"><?php echo e(__('Nombre completo')); ?></label>
                            <input type="text" name="name" id="edit-name" class="form-control rt-ios-input <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('name', $editedUser->name)); ?>" required maxlength="255">
                            <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="rt-label" for="edit-email"><?php echo e(__('Correo electrónico')); ?></label>
                            <input type="email" name="email" id="edit-email" class="form-control rt-ios-input <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('email', $editedUser->email)); ?>" required maxlength="255">
                            <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label class="rt-label" for="edit-password"><?php echo e(__('Nueva contraseña')); ?></label>
                            <div class="rt-edit-password-wrap">
                                <input type="password" name="password" id="edit-password" class="form-control rt-ios-input <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" autocomplete="new-password" placeholder="<?php echo e(__('Dejar en blanco para no cambiar')); ?>">
                                <button type="button" class="rt-password-toggle-btn" data-target="edit-password" title="<?php echo e(__('Mostrar u ocultar contraseña')); ?>" aria-label="<?php echo e(__('Mostrar u ocultar contraseña')); ?>">
                                    <i class="bi bi-eye" aria-hidden="true"></i>
                                </button>
                            </div>
                            <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            <small class="form-text text-muted"><?php echo e(__('Opcional. Mínimo 8 caracteres, mayúscula, minúscula y número.')); ?></small>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="rt-label" for="edit-password-confirmation"><?php echo e(__('Confirmar nueva contraseña')); ?></label>
                            <div class="rt-edit-password-wrap">
                                <input type="password" name="password_confirmation" id="edit-password-confirmation" class="form-control rt-ios-input" autocomplete="new-password">
                                <button type="button" class="rt-password-toggle-btn" data-target="edit-password-confirmation" title="<?php echo e(__('Mostrar u ocultar contraseña')); ?>" aria-label="<?php echo e(__('Mostrar u ocultar contraseña')); ?>">
                                    <i class="bi bi-eye" aria-hidden="true"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="rt-label" for="edit-user-role"><?php echo e(__('Rol')); ?></label>
                        <select name="role_id" id="edit-user-role" class="custom-select form-control rt-ios-input <?php $__errorArgs = ['role_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" required data-organizer-slug="<?php echo e(\App\Models\Role::SLUG_ORGANIZADOR); ?>">
                            <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option
                                    value="<?php echo e($r->id); ?>"
                                    data-slug="<?php echo e($r->slug); ?>"
                                    <?php if((string) old('role_id', $editedUser->role_id) === (string) $r->id): echo 'selected'; endif; ?>
                                ><?php echo e($r->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php $__errorArgs = ['role_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div id="edit-organizer-fields" class="border rounded-lg p-3 bg-light mt-2" style="display: none;">
                        <p class="small font-weight-bold text-dark mb-3"><?php echo e(__('Datos de organizador')); ?></p>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label class="rt-label" for="edit-org"><?php echo e(__('Organización')); ?></label>
                                <input type="text" name="organization_name" id="edit-org" class="form-control rt-ios-input <?php $__errorArgs = ['organization_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('organization_name', $editedUser->organization_name)); ?>" maxlength="255">
                                <?php $__errorArgs = ['organization_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="rt-label" for="edit-phone"><?php echo e(__('Teléfono')); ?></label>
                                <input type="text" name="phone" id="edit-phone" class="form-control rt-ios-input <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('phone', $editedUser->phone)); ?>" maxlength="32">
                                <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label class="rt-label" for="edit-event-type"><?php echo e(__('Tipo principal de evento')); ?></label>
                                <select name="primary_event_type" id="edit-event-type" class="custom-select form-control rt-ios-input <?php $__errorArgs = ['primary_event_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
                                    <option value=""><?php echo e(__('Selecciona…')); ?></option>
                                    <?php $__currentLoopData = \App\Enums\OrganizerPrimaryEventType::cases(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pet): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($pet->value); ?>" <?php if(old('primary_event_type', $editedUser->organizer?->primary_event_type?->value) === $pet->value): echo 'selected'; endif; ?>><?php echo e($pet->label()); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <?php $__errorArgs = ['primary_event_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="rt-label" for="edit-account-status"><?php echo e(__('Estado de la cuenta')); ?></label>
                                <select name="account_status" id="edit-account-status" class="custom-select form-control rt-ios-input <?php $__errorArgs = ['account_status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
                                    <option value=""><?php echo e(__('Selecciona…')); ?></option>
                                    <?php $__currentLoopData = \App\Enums\AccountStatus::cases(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($st->value); ?>" <?php if(old('account_status', $editedUser->account_status?->value) === $st->value): echo 'selected'; endif; ?>><?php echo e(match ($st) {
                                            \App\Enums\AccountStatus::AwaitingReview => __('En revisión'),
                                            \App\Enums\AccountStatus::Approved => __('Aprobado'),
                                            \App\Enums\AccountStatus::Rejected => __('Rechazado'),
                                            \App\Enums\AccountStatus::Inactive => __('Inactivo'),
                                        }); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <?php $__errorArgs = ['account_status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback d-block"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                    </div>

                    <div class="mt-4 d-flex flex-wrap gap-2">
                        <button type="submit" class="btn btn-primary font-weight-bold px-4 rounded-pill"><?php echo e(__('Guardar cambios')); ?></button>
                        <a href="<?php echo e(route('dashboard.users.index')); ?>" class="btn btn-light border rounded-pill px-4"><?php echo e(__('Cancelar')); ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            var sel = document.getElementById('edit-user-role');
            var wrap = document.getElementById('edit-organizer-fields');
            if (!sel || !wrap) return;
            function toggle() {
                var opt = sel.options[sel.selectedIndex];
                var slug = opt ? opt.getAttribute('data-slug') : '';
                var orgSlug = sel.getAttribute('data-organizer-slug') || 'organizador';
                wrap.style.display = slug === orgSlug ? 'block' : 'none';
            }
            sel.addEventListener('change', toggle);
            toggle();
        });

        document.addEventListener('DOMContentLoaded', function () {
            document.querySelectorAll('.rt-password-toggle-btn[data-target]').forEach(function (btn) {
                btn.addEventListener('click', function () {
                    var id = this.getAttribute('data-target');
                    var input = id ? document.getElementById(id) : null;
                    var icon = this.querySelector('i');
                    if (!input || !icon) return;
                    if (input.type === 'password') {
                        input.type = 'text';
                        icon.classList.remove('bi-eye');
                        icon.classList.add('bi-eye-slash');
                    } else {
                        input.type = 'password';
                        icon.classList.remove('bi-eye-slash');
                        icon.classList.add('bi-eye');
                    }
                });
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.dashboard', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/resources/views/dashboard/users/edit.blade.php ENDPATH**/ ?>