<?php $__env->startSection('css'); ?>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css"
          integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw=="
          crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="<?php echo e(asset('assets/web/css/book_now.css')); ?>">
    <!-- ----- new style ----- -->
    <!--    <style>-->

    <!--    </style>-->
<?php $__env->stopSection(); ?>


<?php $__env->startSection('content'); ?>
<section class="hotel_request section-padding bg-light">
        <div class="container">
            <div class="hotel_request_form">
                <div class="form_title">
                    <h3> <?php echo e(__('bookings.hotel_info')); ?> </h3>
                    <div class="steps">
                        <span class="active"></span>
                        <span class="active"></span>
                        <span class=""></span>
                        <span class=""></span>
                    </div>
                </div>
                <form action="<?php echo e(route('checkStep_2')); ?>" method="post" class="add_form">
                    <?php echo csrf_field(); ?>
                <div class="form_body">
                    <div class="row appended_container">
                        <div class="col-lg-4">
                            <div class="form-group">
                                <label for=""> <?php echo e(__('bookings.city')); ?> <span class="text-danger"> * </span> </label>
                                <select name="cities[]" class="form-select form-control" aria-label="Default select example">
                                <?php if(count($cities)): ?>
                                    <?php $__currentLoopData = $cities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $city): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($city->id); ?>"><?php echo e($city->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php endif; ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-lg-3">
                            <div class="form-group check_in">
                                <label for="check_in"> <?php echo e(__('bookings.check_in')); ?> <span class="text-danger"> * </span> </label>
                                <input type="text" id="check_in" name="check_in[]" class="form-control datepicker" placeholder="yyyy-mm-dd">
                            </div>
                        </div>
                        <div class="col-lg-3">
                            <div class="form-group check_out">
                                <label for="check_out"> <?php echo e(__('bookings.check_out')); ?> <span class="text-danger"> * </span> </label>
                                <input type="text" id="check_out" name="check_out[]" class="form-control datepicker" placeholder="yyyy-mm-dd">
                            </div>
                        </div>

                        <?php if(count($cities) > 1): ?>
                        <div class="col-lg-2">
                            <button class="butn color add_c_btn btn btn-secondary add_another_city">
                                <span><?php echo e(__('bookings.add_another_city')); ?></span>
                            </button>
                        </div>
                        <?php endif; ?>
                    </div>
                    <!-- ----- -->
                    <div class="text-center">
                        <button class="butn color my-4 rounded-lg py-3 px-5 w-25 add_button">
                            <span> <i class="fas fa-angle-right mr-2"></i> <?php echo e(__('bookings.next')); ?> </span>
                        </button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </section>
    <?php $__env->stopSection(); ?>

<?php $__env->startSection('inner_js'); ?>

        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

    <script>

        let checkInMecca = "<?php echo e(__('bookings.check_in_mecca')); ?>",
            checkInMadina = "<?php echo e(__('bookings.check_in_madina')); ?>",
            checkOutMecca = "<?php echo e(__('bookings.check_out_mecca')); ?>",
            checkOutMadina = "<?php echo e(__('bookings.check_out_madina')); ?>",
            checkInBoth = "<?php echo e(__('bookings.check_in_madina')); ?>",
            checkOutBoth = "<?php echo e(__('bookings.check_out_both')); ?>",
            addAnotherCity = $('.add_another_city'),
            city = $('select[name="cities[]"]'),
            getCityAndDatesInputsRoute = "<?php echo e(route('getCityAndDatesInputs')); ?>";

        $('.add_button').click(async function (e) {
            e.preventDefault();

            $(this).prop('disabled', true);

            let form = $('.add_form'),
                data = new FormData(form[0]),
                url = form.attr('action'),
                method = form.attr('method');

            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method
            });


            if (response.errors){
                $(this).prop('disabled', false);
                toasterError(response.errors);
            }

            if (response.url){
                window.location.href = response.url;
            }

        });


        $(document).on('click', '.add_another_city', async function (e) {
            e.preventDefault();

            $(this).prop('disabled', true);
            let cityIds = [],
                cities = $(document).find('select');

            cities.each(function () {
                cityIds.push($(this).children('option:selected').val());
            });

            let url = getCityAndDatesInputsRoute,
                data = {city_ids: cityIds},
                method = 'get';

            const response=await ajax({
                url,
                data,
                dataType: 'html',
                method
            });

            if(response){
                $('.appended_container').append(response);
                $(this).remove();
            }


        });

        $(function() {
            $(".datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
        });

        $('body').on('DOMNodeInserted', '.appended_container', function(e) {
            if ($(e.target).find('.datepicker')) {
                $(".datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
            }
        });

    </script>

    <script>
    $( function() {
      $.widget( "custom.combobox", {
        _create: function() {
          this.wrapper = $( "<span>" )
            .addClass( "custom-combobox" )
            .insertAfter( this.element );

          this.element.hide();
          this._createAutocomplete();
          this._createShowAllButton();
        },

        _createAutocomplete: function() {
          var selected = this.element.children( ":selected" ),
            value = selected.val() ? selected.text() : "";

          this.input = $( "<input>" )
            .appendTo( this.wrapper )
            .val( value )
            .attr( "title", "" )
            .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
            .autocomplete({
              delay: 0,
              minLength: 0,
              source: this._source.bind( this )
            })
            .tooltip({
              classes: {
                "ui-tooltip": "ui-state-highlight"
              }
            });

          this._on( this.input, {
            autocompleteselect: function( event, ui ) {
              ui.item.option.selected = true;
              this._trigger( "select", event, {
                item: ui.item.option
              });
            },

            autocompletechange: "_removeIfInvalid"
          });
        },

        _createShowAllButton: function() {
          var input = this.input,
            wasOpen = false;

          $( "<a>" )
            .attr( "tabIndex", -1 )
            // .attr( "title", "Show All Items" )
            .tooltip()
            .appendTo( this.wrapper )
            .button({
              icons: {
                primary: "ui-icon-triangle-1-s"
              },
              text: false
            })
            .removeClass( "ui-corner-all" )
            .addClass( "custom-combobox-toggle ui-corner-right" )
            .on( "mousedown", function() {
              wasOpen = input.autocomplete( "widget" ).is( ":visible" );
            })
            .on( "click", function() {
              input.trigger( "focus" );

              // Close if already visible
              if ( wasOpen ) {
                return;
              }

              // Pass empty string as value to search for, displaying all results
              input.autocomplete( "search", "" );
            });
        },

        _source: function( request, response ) {
          var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
          response( this.element.children( "option" ).map(function() {
            var text = $( this ).text();
            if ( this.value && ( !request.term || matcher.test(text) ) )
              return {
                label: text,
                value: text,
                option: this
              };
          }) );
        },

        _removeIfInvalid: function( event, ui ) {

          // Selected an item, nothing to do
          if ( ui.item ) {
            return;
          }

          // Search for a match (case-insensitive)
          var value = this.input.val(),
            valueLowerCase = value.toLowerCase(),
            valid = false;
          this.element.children( "option" ).each(function() {
            if ( $( this ).text().toLowerCase() === valueLowerCase ) {
              this.selected = valid = true;
              return false;
            }
          });

          // Found a match, nothing to do
          if ( valid ) {
            return;
          }

          // Remove invalid value
          this.input
            .val( "" )
            .attr( "title", value + " didn't match any item" )
            .tooltip( "open" );
          this.element.val( "" );
          this._delay(function() {
            this.input.tooltip( "close" ).attr( "title", "" );
          }, 2500 );
          this.input.autocomplete( "instance" ).term = "";
        },

        _destroy: function() {
          this.wrapper.remove();
          this.element.show();
        }
      });

      $( "#country_id" ).combobox();
      $( "#toggle" ).on( "click", function() {
        $( "#country_id" ).toggle();
      });
    } );
    </script>


<?php $__env->stopSection(); ?>

<?php echo $__env->make('web.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nesmaalyomhost/public_html/mawada/resources/views/web/bookings/step_2.blade.php ENDPATH**/ ?>