<?php $__env->startSection('title', isset($empleado) ? 'Editar Empleado' : 'Nuevo Empleado'); ?>
<?php $__env->startSection('content'); ?>
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
    <div class="card-header">
        <i class="bi bi-person me-1"></i>
        <?php echo e(isset($empleado) ? 'Editar: '.$empleado->nombre : 'Nuevo Empleado'); ?>

    </div>
    <div class="card-body">
        <form action="<?php echo e(isset($empleado) ? route('empleados.update', $empleado) : route('empleados.store')); ?>"
              method="POST">
            <?php echo csrf_field(); ?>
            <?php if(isset($empleado)): ?> <?php echo method_field('PUT'); ?> <?php endif; ?>

            <div class="row g-3">
                <div class="col-md-8">
                    <label class="form-label fw-semibold">Nombre completo <span class="text-danger">*</span></label>
                    <input type="text" name="nombre" class="form-control <?php $__errorArgs = ['nombre'];
$__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('nombre', $empleado->nombre ?? '')); ?>" required>
                    <?php $__errorArgs = ['nombre'];
$__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"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
                <div class="col-md-4">
                    <label class="form-label fw-semibold">Cédula <span class="text-danger">*</span></label>
                    <input type="text" name="cedula" class="form-control <?php $__errorArgs = ['cedula'];
$__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('cedula', $empleado->cedula ?? '')); ?>" required>
                    <?php $__errorArgs = ['cedula'];
$__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"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
                <div class="col-md-6">
                    <label class="form-label fw-semibold">Cargo</label>
                    <input type="text" name="cargo" class="form-control"
                           value="<?php echo e(old('cargo', $empleado->cargo ?? '')); ?>">
                </div>
                <div class="col-md-6">
                    <label class="form-label fw-semibold">Salario base</label>
                    <div class="input-group">
                        <span class="input-group-text">$</span>
                        <input type="number" name="salario" step="100" min="0" class="form-control"
                               value="<?php echo e(old('salario', $empleado->salario ?? 0)); ?>">
                    </div>
                </div>

                <div class="col-12"><hr class="my-1"><h6 class="text-muted">Beneficios</h6></div>

                <div class="col-md-4">
                    <label class="form-label">Medicina prepagada / mes</label>
                    <div class="input-group">
                        <span class="input-group-text">$</span>
                        <input type="number" name="medicina_prepagada" step="100" min="0" class="form-control"
                               value="<?php echo e(old('medicina_prepagada', $empleado->medicina_prepagada ?? 0)); ?>">
                    </div>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Auxilio alimentación / mes</label>
                    <div class="input-group">
                        <span class="input-group-text">$</span>
                        <input type="number" name="alimentacion" step="100" min="0" class="form-control"
                               value="<?php echo e(old('alimentacion', $empleado->alimentacion ?? 0)); ?>">
                    </div>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Zafiro / mes</label>
                    <div class="input-group">
                        <span class="input-group-text">$</span>
                        <input type="number" name="zafiro" step="100" min="0" class="form-control"
                               value="<?php echo e(old('zafiro', $empleado->zafiro ?? 0)); ?>">
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="form-check mt-3">
                        <input type="hidden" name="activo" value="0">
                        <input type="checkbox" name="activo" value="1" class="form-check-input" id="chkActivo"
                               <?php echo e(old('activo', $empleado->activo ?? true) ? 'checked' : ''); ?>>
                        <label class="form-check-label" for="chkActivo">Empleado activo</label>
                    </div>
                </div>

                <div class="col-12"><hr class="my-1"><h6 class="text-muted">Acceso al sistema (opcional)</h6></div>
                <?php if(!isset($empleado)): ?>
                <div class="col-md-1">
                    <div class="form-check mt-2">
                        <input type="checkbox" name="crear_usuario" value="1" class="form-check-input"
                               id="chkUsuario" onchange="document.getElementById('bloqueUsuario').style.display=this.checked?'flex':'none'">
                        <label class="form-check-label" for="chkUsuario">Crear</label>
                    </div>
                </div>
                <div class="col-11 row g-2" id="bloqueUsuario" style="display:none">
                    <div class="col-md-4">
                        <input type="email" name="email" class="form-control" placeholder="Email de acceso">
                    </div>
                    <div class="col-md-4">
                        <input type="password" name="password" class="form-control" placeholder="Contraseña (vacío = cédula)">
                    </div>
                    <div class="col-md-4">
                        <select name="rol" class="form-select">
                            <option value="empleado">Empleado</option>
                            <option value="sst">SST (reportes)</option>
                            <option value="supervisor">Supervisor</option>
                            <option value="admin">Administrador</option>
                        </select>
                    </div>
                </div>
                <?php else: ?>
                
                <?php if($empleado->user): ?>
                <div class="col-md-4">
                    <label class="form-label small text-muted">Email</label>
                    <input type="email" name="email" class="form-control"
                           value="<?php echo e(old('email', $empleado->user->email)); ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label small text-muted">Rol</label>
                    <select name="rol" class="form-select">
                        <option value="empleado"   <?php echo e($empleado->user->rol==="empleado"   ? "selected" : ""); ?>>Empleado</option>
                        <option value="sst"        <?php echo e($empleado->user->rol==="sst"        ? "selected" : ""); ?>>SST (reportes)</option>
                        <option value="supervisor" <?php echo e($empleado->user->rol==="supervisor" ? "selected" : ""); ?>>Supervisor</option>
                        <option value="admin"      <?php echo e($empleado->user->rol==="admin"      ? "selected" : ""); ?>>Administrador</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <label class="form-label small text-muted">Nueva contraseña (vacío = sin cambio)</label>
                    <input type="password" name="password" class="form-control" placeholder="Dejar vacío para no cambiar">
                </div>
                <?php endif; ?>
                <?php endif; ?>

                <div class="col-12 d-flex gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-save me-1"></i>
                        <?php echo e(isset($empleado) ? 'Actualizar' : 'Guardar'); ?>

                    </button>
                    <a href="<?php echo e(route('empleados.index')); ?>" class="btn btn-outline-secondary">Cancelar</a>
                </div>
            </div>
        </form>
    </div>
</div>
</div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/evolucionamos/public_html/ges-chronos/app/hoja-tiempo/resources/views/empleados/edit.blade.php ENDPATH**/ ?>