
<?php $__env->startSection('contenido'); ?>
<div class="content">
	<div class="card">
		<div class="card-header header-elements-inline">
			<h5 class="card-title">NUEVA ASIGNACIÓN DE TERRITORIO</h5>
			<div class="header-elements">
				<div class="list-icons">
				    <a class="list-icons-item" data-action="collapse"></a>
				</div>
			</div>
		</div>

		<div class="card-body">
			<form action="<?php echo e(route('territorio.actualizar',$planTrabajo->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <fieldset>
                    <div class="collapse show">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="">APM</label>
                                    <select class="form-control" name="id_apm">
                                        <?php $__currentLoopData = $apms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $apm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option <?php echo e($planTrabajo->id_apm == $apm['id'] ? "selected" : ""); ?> value="<?php echo e($apm['id']); ?>"><?php echo e($apm['primer_nombre']); ?> <?php echo e($apm['segundo_nombre']); ?> <?php echo e($apm['primer_apellido']); ?> <?php echo e($apm['segundo_apellido']); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <input type="hidden" id="id_gira" name="id_gira" value="<?php echo e($giraPlan->id); ?>">
                                <div class="form-group">
                                    <label for="">País</label>
                                    <input type="text" class="form-control" id="pais" value="<?php echo e($giraPlan->region->pais->descripcion_pais); ?>" name="pais" placeholder="" readonly>
                                </div>
                            </div>
                            <div class="col-md-6">

                                <div class="form-group">
                                    <label for="">Región</label>
                                    <input type="text" class="form-control" id="region" value="<?php echo e($giraPlan->region->descripcion_region); ?>" name="region" placeholder="" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="">Gira</label>
                                    <input type="text" class="form-control" id="gira" value="<?php echo e($giraPlan->descripcion_gira); ?>" name="gira" placeholder="" readonly>
                                </div>
                                <a class="btn btn-success"  data-toggle="modal" data-target="#tablaCodigoArea">Buscar <i class="icon-search4 ml-2"></i></a>
                            </div>
                        </div>
                    </div>
                </fieldset>

				<div class="text-right">
					<button type="submit" class="btn btn-primary">Guardar asignación<i class="icon-floppy-disk ml-2"></i></button>
				</div>
            </form>

		</div>
	</div>

</div>

<div class="modal fade" id="tablaCodigoArea" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <table id="tablaJS" class="table datatable-basic">
                    <thead>
                        <tr>
                            <th>id</th>
                            <th>País</th>
                            <th>Región</th>
                            <th>Gira</th>
                            <th class="text-center">Acciones</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $giras; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $gira): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="id_gira"><?php echo e($gira->id); ?></td>
                                <td class="pais"><?php echo e($gira->region->pais->descripcion_pais); ?></td>
                                <td class="region"><?php echo e($gira->region->descripcion_region); ?></td>
                                <td class="gira"><?php echo e($gira->descripcion_gira); ?></td>
                                <td><button onclick="guardarGira(this)" class='btn btn-success seleccionarCodigoArea'>Seleccionar</button></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('javascript'); ?>
<script>
    function guardarGira(elemento){
        const padre=elemento.parentElement.parentElement;
        const id_gira=padre.getElementsByClassName('id_gira')[0].innerText;
        const pais=padre.getElementsByClassName('pais')[0].innerText;
        const region=padre.getElementsByClassName('region')[0].innerText;
        const gira=padre.getElementsByClassName('gira')[0].innerText;

        document.getElementById('pais').value=pais;
        document.getElementById('region').value=region;
        document.getElementById('gira').value=gira;
        document.getElementById('id_gira').value=id_gira;

        $('#tablaCodigoArea').modal('hide');
        
    }
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\jarvis\resources\views/distribucion_territorios/editar.blade.php ENDPATH**/ ?>