<form class="field_form shipping_calculator" id="miFormulario">
    <?php echo csrf_field(); ?>
    <input type="hidden" name="type" id="type" value="<?php echo e($type); ?>"/>

    <div class="form-row row">
        <div class="form-group col-lg-6">
            <div class="custom_select">
                <select class="select2" name="origin" id="origin" placeholder="<?php echo e(__('messages.leaving_from')); ?>" required="required" style="width: 100%">
                    <option value=""><?php echo e(__('messages.select_leaving_from')); ?></option>
                    <?php $__currentLoopData = $origins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $origins): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($origins->id); ?>"><?php echo e($origins->hours); ?> | <?php echo e($origins->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
        </div>
        <div class="form-group col-lg-6">
            <div class="custom_select">
                <select class="select2" name="destination" id="destination" placeholder="<?php echo e(__('messages.destination')); ?>" required="required" style="width: 100%;"></select>    
            </div>    
        </div>
    </div>

    <div class="form-row row">
        <div class="form-group col-lg-6">   
            <div class="custom_select">         
                <input type="text" name="departure_date" id="departure_date" placeholder="<?php echo e(__('messages.departure_date')); ?>" style="font-weight: bold"> 
            </div>
        </div>
        <div class="form-group col-lg-6">
            <div class="custom_select">         
                <input type="text" name="pax_number" id="pax_number" placeholder="<?php echo e(__('messages.pax')); ?>" required="required" style="font-weight: bold" class="numeric" value="1"> 
            </div>
        </div>
    </div>    

    <div class="form-row row">
        <div class="form-group col-lg-6">   
            <div class="custom_select">         
                <input type="text" name="pickup_place" id="pickup_place" placeholder="<?php echo e(__('messages.pickup_place')); ?>" required="required" style="font-weight: bold"> 
            </div>
        </div>
        <div class="form-group col-lg-6">
            <div class="custom_select">         
                <input type="text" name="arival_place" id="arival_place" placeholder="<?php echo e(__('messages.arival_place')); ?>" required="required" style="font-weight: bold"> 
            </div>
        </div>
    </div>      
    
    <hr>

    <p style="font-weight: bold"><?php echo e(__('messages.personal_general_information')); ?></p><br>
    
    <div class="form-row row">
        <div class="form-group col-lg-6">   
            <div class="custom_select">         
                <input type="text" name="first_name" id="first_name" placeholder="<?php echo e(__('messages.first_name')); ?>" style="font-weight: bold"> 
            </div>
        </div>
        <div class="form-group col-lg-6">
            <div class="custom_select">         
                <input type="text" name="last_name" id="last_name" placeholder="<?php echo e(__('messages.last_name')); ?>" required="required" style="font-weight: bold"> 
            </div>
        </div>
    </div>
    
    <div class="form-row row">
        <div class="form-group col-lg-6">   
            <div class="custom_select">         
                <input type="email" name="email" id="email" placeholder="<?php echo e(__('messages.email')); ?>" style="font-weight: bold"> 
            </div>
        </div>
        <div class="form-group col-lg-6">
            <div class="custom_select">         
                <input type="text" name="phone" id="phone" placeholder="<?php echo e(__('messages.phone')); ?>" style="font-weight: bold"> 
            </div>
        </div>
    </div>      

    <?php echo $__env->make('livewire.partial.row-total', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

    
    <div class="form-row row">
        <div class="col-md-2 offset-md-10 text-right">
            <button class="btn btn-sm pull-right" id="enviarFormulario">
                <i class="fi-rs-label mr-10"></i>Enviar
            </button>
        </div>
    </div>
</form>

<div id="resultado"></div>

<?php
    $message_destination = trans('messages.select_destination');
?>

<?php 
/*
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
*/
?>
<script>
    $(document).ready(function () {

        var destinationCallInProgress = false;

        $("#enviarFormulario").click(function (e) {
            e.stopPropagation();
            var formData = $("#miFormulario").serialize();

            $.ajax({
                url: "<?php echo e(route('home.process')); ?>",
                type: "POST",
                data: formData,
                success: function (response) {
                    $("#resultado").html(response);
                }
            });
        });

        $(".select2").select2({
            width: 'resolve' // need to override the changed default
        });

        $('#origin').change(function(e) {
            e.stopPropagation();
            var originId = $(this).val();
            
            // Realiza la petición AJAX para obtener los destinos basados en el origen seleccionado
            $.ajax({
                url: '/get-destinations/' + originId, // Ruta en Laravel para obtener destinos
                method: 'GET',
                success: function(data) {
                    $('#destination').empty();

                    $('#destination').append('<option value="">' + "<?php echo e($message_destination); ?>" + '</option>');
                    $.each(data, function(key, value) {
                        $('#destination').append('<option value="' + key + '">' + value + '</option>');
                    });
                    $('#destination').trigger('change');
                }
            });
        });

        $('#destination').change(function(e) {
            e.stopPropagation();
            if (!destinationCallInProgress)
            {
                destinationCallInProgress = true;
                var originId = $("#origin").val();           
                var destinationId = $(this).val();
                var pax = $("#pax_number").val();
                var type = $("#type").val();
                
                // Realiza la petición AJAX para obtener los destinos basados en el origen seleccionado
                $.ajax({
                    url: '/get-total',
                    method: 'GET',        
                    data: {
                        originId: originId,
                        destinationId: destinationId,
                        pax: pax,
                        type: type
                    },
                    success: function(data) {
                        $("#subtotal_rac").html(data.subtotal_rac);
                        $("#tax_rac").html(data.tax_rac);
                        $("#total_rac").html(data.total_rac);
                        $("#subtotal_neto").html(data.subtotal_neto);
                        $("#tax_neto").html(data.tax_neto);
                        $("#total_neto").html(data.total_neto);
                    },
                    complete: function() {
                        destinationCallInProgress = false;
                    }
                });
            }
        });

        $("#departure_date").datepicker({
            dateFormat: 'dd/mm/yy'
        });

        $('.numeric').on('input', function() {
            // Eliminar cualquier caracter no numérico

            var value = $(this).val().replace(/[^0-9]/g, '');
        
            // Limitar la longitud a 3 caracteres
            if (value.length > 3) {
                value = value.slice(0, 3);
            }
            
            $(this).val(value);
        });

        
    });
</script><?php /**PATH C:\wamp\www\laraveltarifario\resources\views/livewire/partial/form.blade.php ENDPATH**/ ?>