<?php $__env->startSection('title', 'Editar Registro Migrado'); ?>

<?php
    $returnUrl = $returnToken !== '' ? route('admin.reportedemigracion.show', $returnToken) : route('admin.reportedemigracion.index');
    $detailParentField = (int) $item->tipo_movimiento === 1 ? 'id_codigo_ingreso' : 'id_codigo_egreso';
?>

<?php $__env->startSection('content'); ?>
<style>
    .edit-card {
        background: #fff;
        border: 1px solid #d7e0ea;
        border-radius: 18px;
        box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
        overflow: hidden;
    }

    .edit-card-header {
        background: linear-gradient(90deg, #1d4f7d 0%, #3678ad 100%);
        color: #fff;
        font-size: 1rem;
        font-weight: 800;
        padding: 16px 22px;
    }

    .edit-card-body {
        padding: 22px;
    }

    .edit-section {
        border: 1px solid #e2e8f0;
        border-radius: 16px;
        padding: 18px;
        margin-bottom: 18px;
        background: #fbfdff;
    }

    .edit-section-title {
        color: #0f3d68;
        font-size: .9rem;
        font-weight: 800;
        margin-bottom: 14px;
        text-transform: uppercase;
    }
</style>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-xl-11">
            <div class="edit-card">
                <div class="edit-card-header">EDITAR REGISTRO DE MIGRACION BANCARIA</div>
                <div class="edit-card-body">
                    <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
                        <div>
                            <h4 class="mb-0"><?php echo e($item->nombre_archivo); ?></h4>
                            <small class="text-muted">Tipo: <?php echo e($tipoMovimientoLabel); ?> | ID: <?php echo e($item->id); ?></small>
                        </div>
                        <a href="<?php echo e($returnUrl); ?>" class="btn btn-outline-secondary btn-sm">
                            <i class="fas fa-arrow-left me-1"></i>Volver
                        </a>
                    </div>

                    <form method="POST" action="<?php echo e(route('admin.reportedemigracion.update', $item->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>
                        <input type="hidden" name="return_token" value="<?php echo e($returnToken); ?>">

                        <div class="edit-section">
                            <div class="edit-section-title">Datos Del Movimiento</div>
                            <div class="row g-3">
                                <div class="col-md-4">
                                    <label class="form-label">Fecha Migracion</label>
                                    <input type="datetime-local" name="fecha_migracion" class="form-control <?php $__errorArgs = ['fecha_migracion'];
$__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('fecha_migracion', $item->created_at ? \Carbon\Carbon::parse($item->created_at)->format('Y-m-d\TH:i') : '')); ?>">
                                    <?php $__errorArgs = ['fecha_migracion'];
$__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">Fecha Operacion</label>
                                    <input type="date" name="fecha_operacion" class="form-control <?php $__errorArgs = ['fecha_operacion'];
$__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('fecha_operacion', $item->fecha_operacion ? \Carbon\Carbon::parse($item->fecha_operacion)->format('Y-m-d') : '')); ?>">
                                    <?php $__errorArgs = ['fecha_operacion'];
$__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">Tipo Moneda</label>
                                    <select name="tipo_moneda" class="form-select <?php $__errorArgs = ['tipo_moneda'];
$__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="1" <?php if((int) old('tipo_moneda', $item->tipo_moneda) === 1): echo 'selected'; endif; ?>>SOLES</option>
                                        <option value="2" <?php if((int) old('tipo_moneda', $item->tipo_moneda) === 2): echo 'selected'; endif; ?>>DOLARES</option>
                                    </select>
                                    <?php $__errorArgs = ['tipo_moneda'];
$__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">Tipo Cambio</label>
                                    <input type="number" step="0.0001" name="tipo_cambio" class="form-control <?php $__errorArgs = ['tipo_cambio'];
$__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('tipo_cambio', $item->tipo_cambio)); ?>">
                                    <?php $__errorArgs = ['tipo_cambio'];
$__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-8">
                                    <label class="form-label">Proyecto</label>
                                    <select name="id_proyecto" class="form-select <?php $__errorArgs = ['id_proyecto'];
$__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="">Seleccione</option>
                                        <?php $__currentLoopData = $projects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $project): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($project->id); ?>" <?php if((int) old('id_proyecto', $item->id_proyecto) === (int) $project->id): echo 'selected'; endif; ?>><?php echo e($project->codigo); ?> - <?php echo e($project->nombre); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['id_proyecto'];
$__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-3">
                                    <label class="form-label">Nro Operacion</label>
                                    <input type="text" name="numero_operacion" class="form-control <?php $__errorArgs = ['numero_operacion'];
$__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('numero_operacion', $item->numero_operacion)); ?>">
                                    <?php $__errorArgs = ['numero_operacion'];
$__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-3">
                                    <label class="form-label">Codigo Banco</label>
                                    <input type="text" name="codigo_banco" class="form-control <?php $__errorArgs = ['codigo_banco'];
$__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('codigo_banco', $item->codigo_banco)); ?>">
                                    <?php $__errorArgs = ['codigo_banco'];
$__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-3">
                                    <label class="form-label">Codigo Ing/Egr</label>
                                    <input type="text" name="codigo_ingreso_egreso" class="form-control <?php $__errorArgs = ['codigo_ingreso_egreso'];
$__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('codigo_ingreso_egreso', $item->codigo_ingreso_egreso)); ?>">
                                    <?php $__errorArgs = ['codigo_ingreso_egreso'];
$__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-3">
                                    <label class="form-label">Tipo Movimiento</label>
                                    <input type="text" class="form-control" value="<?php echo e($tipoMovimientoLabel); ?>" readonly>
                                </div>

                                <div class="col-md-6">
                                    <label class="form-label"><?php echo e((int) $item->tipo_movimiento === 1 ? 'Codigo Ingreso' : 'Codigo Egreso'); ?></label>
                                    <select name="id_codigoingreso" id="id_codigoingreso" class="form-select <?php $__errorArgs = ['id_codigoingreso'];
$__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="">Seleccione</option>
                                        <?php $__currentLoopData = $codes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $code): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($code->id); ?>" <?php if((int) old('id_codigoingreso', $item->id_codigoingreso) === (int) $code->id): echo 'selected'; endif; ?>><?php echo e($code->codigo); ?> - <?php echo e($code->nombre); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['id_codigoingreso'];
$__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"><?php echo e((int) $item->tipo_movimiento === 1 ? 'Detalle Ingreso' : 'Detalle Egreso'); ?></label>
                                    <select name="id_codigoingresodetalle" id="id_codigoingresodetalle" class="form-select <?php $__errorArgs = ['id_codigoingresodetalle'];
$__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="">Seleccione</option>
                                        <?php $__currentLoopData = $details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($detail->id); ?>"
                                                    data-parent="<?php echo e($detail->{$detailParentField}); ?>"
                                                    <?php if((int) old('id_codigoingresodetalle', $item->id_codigoingresodetalle) === (int) $detail->id): echo 'selected'; endif; ?>>
                                                <?php echo e($detail->codigo); ?> - <?php echo e($detail->nombre); ?>

                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['id_codigoingresodetalle'];
$__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-12">
                                    <label class="form-label">Descripcion</label>
                                    <textarea name="descripcion" rows="3" class="form-control <?php $__errorArgs = ['descripcion'];
$__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); ?>"><?php echo e(old('descripcion', $item->descripcion)); ?></textarea>
                                    <?php $__errorArgs = ['descripcion'];
$__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-3">
                                    <label class="form-label">Monto Soles</label>
                                    <input type="number" step="0.01" name="monto" class="form-control <?php $__errorArgs = ['monto'];
$__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('monto', $item->monto)); ?>">
                                    <?php $__errorArgs = ['monto'];
$__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-3">
                                    <label class="form-label">Monto Dolares</label>
                                    <input type="number" step="0.01" name="monto_dolar" class="form-control <?php $__errorArgs = ['monto_dolar'];
$__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('monto_dolar', $item->monto_dolar)); ?>">
                                    <?php $__errorArgs = ['monto_dolar'];
$__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>
                        </div>

                        <div class="d-flex justify-content-end gap-2">
                            <a href="<?php echo e($returnUrl); ?>" class="btn btn-outline-secondary">Cancelar</a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save me-1"></i>Guardar Cambios
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const codeSelect = document.getElementById('id_codigoingreso');
        const detailSelect = document.getElementById('id_codigoingresodetalle');

        if (!codeSelect || !detailSelect) {
            return;
        }

        const allOptions = Array.from(detailSelect.querySelectorAll('option')).map((option) => ({
            value: option.value,
            label: option.textContent,
            parent: option.dataset.parent || '',
            selected: option.selected,
        }));

        const refreshDetails = () => {
            const selectedCode = codeSelect.value;
            const currentValue = detailSelect.value;

            detailSelect.innerHTML = '';

            const placeholder = document.createElement('option');
            placeholder.value = '';
            placeholder.textContent = 'Seleccione';
            detailSelect.appendChild(placeholder);

            allOptions.forEach((item) => {
                if (!item.value || (selectedCode && item.parent !== selectedCode)) {
                    return;
                }

                const option = document.createElement('option');
                option.value = item.value;
                option.textContent = item.label;
                if (item.value === currentValue || item.selected) {
                    option.selected = true;
                }
                detailSelect.appendChild(option);
            });

            if (selectedCode && !Array.from(detailSelect.options).some((option) => option.value === currentValue)) {
                detailSelect.value = '';
            }
        };

        codeSelect.addEventListener('change', refreshDetails);
        refreshDetails();
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/seminari/public_html/seminario/resources/views/Banco/reportedemigracion/edit.blade.php ENDPATH**/ ?>