PageSourceSearch

https://intercoastalsafaris.com/wp-content/plugins/listeo-core/assets/js/bookings.js?ver=1.9.40

js intercoastalsafaris.com collected 2026-10-04 05:25:13 UTC 74,623 bytes, 2,350 lines download raw bytes

1/* ----------------- Start Document ----------------- */
2(function($){
3"use strict";
4
5$(document).ready(function(){
6  var inputClicked = false;
7  /*----------------------------------------------------*/
8  /*  Booking widget and confirmation form
9	/*----------------------------------------------------*/
10  $("a.booking-confirmation-btn").on("click", function (e) {
11    e.preventDefault();
12    var bookingForm = $("#booking-confirmation");
13    if (bookingForm[0].checkValidity()) {
14      var button = $(this);
15      button.addClass("loading");
16      $("#booking-confirmation").submit();
17    }
18  });
19
20  // reload states based on country
21
22  $("#billing_country").change(function () {
23    var country = $(this).val();
24
25    $.ajax({
26      url: listeo.ajaxurl, // WordPress AJAX
27      type: "POST",
28      data: {
29        action: "listeo_get_booking_states",
30        country: country,
31      },
32      success: function (response) {
33        var select = $("#billing_state");
34        var states = response.data;
35
36        if (states) {
37          select.find("option:not(:first)").remove();
38          $.each(states, function (key, value) {
39            select.append('<option value="' + key + '">' + value + "</option>");
40          });
41        } else {
42          select.find("option:not(:first)").remove();
43          // remove required attribute
44          select.removeAttr("required");
45        }
46      },
47    });
48  });
49  $(document).bind("change", function (e) {
50    if (e.target.checkValidity && !e.target.checkValidity()) {
51      $(e.target).parent().addClass("invalid");
52    } else {
53      $(e.target).parent().removeClass("invalid");
54    }
55  });
56
57  $("#listeo-coupon-link").on("click", function (e) {
58    e.preventDefault();
59    $(".coupon-form").toggle();
60  });
61
62  function validate_coupon(listing_id, price) {
63    var current_codes = $("#coupon_code").val();
64    if (current_codes) {
65      var codes = current_codes.split(",");
66      $.each(codes, function (index, item) {
67        console.log(item);
68        var ajax_data = {
69          listing_id: listing_id,
70          coupon: item,
71          coupons: codes,
72          price: price,
73          action: "listeo_validate_coupon",
74        };
75        $.ajax({
76          type: "POST",
77          dataType: "json",
78          url: listeo.ajaxurl,
79          data: ajax_data,
80
81          success: function (data) {
82            if (data.success) {
83            } else {
84              $("#coupon-widget-wrapper-output div.error")
85                .html(data.message)
86                .show();
87              $(
88                '#coupon-widget-wrapper-applied-coupons span[data-coupon="' +
89                  item +
90                  '"] i'
91              ).trigger("click");
92              $("#apply_new_coupon").val("");
93              $("#coupon-widget-wrapper-output .error").delay(3500).hide(500);
94            }
95            $("a.listeo-booking-widget-apply_new_coupon").removeClass("active");
96          },
97        });
98      });
99    }
100  }
101
102  // Apply new coupon
103  $("a.listeo-booking-widget-apply_new_coupon").on("click", function (e) {
104    e.preventDefault();
105    $(this).addClass("active");
106    $("#coupon-widget-wrapper-output div").hide();
107
108   
109
110    //check if it was already addd
111    var price = $(".booking-estimated-cost").data("price");
112    if (typeof price === "undefined" || price === null) {
113      price = $(".total-costs").data("price");
114    }
115
116    var current_codes = $("#coupon_code").val();
117    var result = current_codes.split(",");
118    var arraycontainscoupon = result.indexOf($("#apply_new_coupon").val()) > -1;
119    var ajax_data = {
120      listing_id: $("#listing_id").val(),
121      coupon: $("#apply_new_coupon").val(),
122      coupons: current_codes,
123      price: price,
124      action: "listeo_validate_coupon",
125
126    };
127    $("#coupon-widget-wrapper-output div").hide();
128    if (arraycontainscoupon) {
129      $(this).removeClass("active");
130      $("input#apply_new_coupon").removeClass("bounce").addClass("bounce");
131      return;
132    }
133    $.ajax({
134      type: "POST",
135      dataType: "json",
136      url: listeo.ajaxurl,
137      data: ajax_data,
138
139      success: function (data) {
140        if (data.success) {
141          if (current_codes.length > 0) {
142            $("#coupon_code").val(current_codes + "," + data.coupon);
143          } else {
144            $("#coupon_code").val(data.coupon);
145          }
146          $("#apply_new_coupon").val("");
147          $("#coupon-widget-wrapper-applied-coupons").append(
148            "<span data-coupon=" +
149              data.coupon +
150              ">" +
151              data.coupon +
152              "<i class='fa fa-times'></i></span>"
153          );
154          $("#coupon-widget-wrapper-output .success").show();
155          if ($("#booking-confirmation-summary").length > 0) {
156            calculate_booking_form_price();
157          } else {
158            if ($("#form-booking").hasClass("form-booking-event")) {
159              calculate_price();
160            } else {
161              check_booking();
162            }
163          }
164          $("#coupon-widget-wrapper-output .success").delay(3500).hide(500);
165        } else {
166          $("input#apply_new_coupon").removeClass("bounce").addClass("bounce");
167          $("#coupon-widget-wrapper-output div.error")
168            .html(data.message)
169            .show();
170
171          $("#apply_new_coupon").val("");
172          $("#coupon-widget-wrapper-output .error").delay(3500).hide(500);
173        }
174        $("a.listeo-booking-widget-apply_new_coupon").removeClass("active");
175      },
176    });
177  });
178
179  // Remove coupon from widget and calculate price again
180  $("#coupon-widget-wrapper-applied-coupons").on(
181    "click",
182    "span i",
183    function (e) {
184      var coupon = $(this).parent().data("coupon");
185
186      var coupons = $("#coupon_code").val();
187      var coupons_array = coupons.split(",");
188      coupons_array = coupons_array.filter(function (item) {
189        return item !== coupon;
190      });
191
192      $("#coupon_code").val(coupons_array.join(","));
193      $(this).parent().remove();
194      if ($("#booking-confirmation-summary").length > 0) {
195        calculate_booking_form_price();
196      } else {
197        check_booking();
198        calculate_price();
199      }
200    }
201  );
202
203  //Book now button
204  $(".listing-widget").on("click", "a.book-now", function (e) {
205    var button = $(this);
206
207    if ($("#date-picker").val()) {
208      inputClicked = true;
209
210      if ($(".time-picker").length && !$(".time-picker").val()) {
211        inputClicked = false;
212      }
213      if ($("#slot").length && !$("#slot").val()) {
214        inputClicked = false;
215      }
216      if (inputClicked) {
217        check_booking();
218      }
219    }
220
221    if (inputClicked == false) {
222      $(
223        ".time-picker,.time-slots-dropdown,.date-picker-listing-rental"
224      ).addClass("bounce");
225    } else {
226      button.addClass("loading");
227    }
228    e.preventDefault();
229
230    var freeplaces = button.data("freeplaces");
231
232    // var checked = $(".bookable-services input[type=checkbox]:checked").length;
233
234    // if (!checked) {
235    // 	alert("You must select at least one extra service.");
236    // 	return false;
237    // }
238
239    setTimeout(function () {
240      button.removeClass("loading");
241      $(
242        ".time-picker,.time-slots-dropdown,.date-picker-listing-rental"
243      ).removeClass("bounce");
244    }, 3000);
245
246    try {
247      // Calculate total guests
248      var adults = parseInt($(".adults").val()) || 0;
249      var children = parseInt($("input[name=childrenQtyInput]").val()) || 0;
250      var infants = parseInt($("input[name=infantsQtyInput]").val()) || 0;
251      var animals = parseInt($("input[name=animalsQtyInput]").val()) || 0;
252      
253      // Get max guests from the form
254      var maxGuests = parseInt($(".adults").data("max"));
255      
256      // Calculate total counting guests (adults + children count towards max, infants and animals don't)
257      var totalCountingGuests = adults + children;
258      
259      if (totalCountingGuests > maxGuests) {
260        $("#booking-widget-message").show().html(listeo_core.exceed_guests_limit);
261        return false;
262      }
263
264      if (freeplaces > 0) {
265        // preparing data for ajax to send to booking form
266
267        if ($("#date-picker").data("rental-timepicker")) {
268          // var startDataSQL need to have hour
269          var startDataSql = moment(
270            $("#date-picker").data("daterangepicker").startDate,
271            ["MM/DD/YYYY hh:mm A"]
272          ).format("YYYY-MM-DD HH:mm:ss");
273          var endDataSql = moment(
274            $("#date-picker").data("daterangepicker").endDate,
275            ["MM/DD/YYYY hh:mm A"]
276          ).format("YYYY-MM-DD HH:mm:ss");
277        } else {
278          var startDataSql = moment(
279            $("#date-picker").data("daterangepicker").startDate,
280            ["MM/DD/YYYY"]
281          ).format("YYYY-MM-DD");
282          var endDataSql = moment(
283            $("#date-picker").data("daterangepicker").endDate,
284            ["MM/DD/YYYY"]
285          ).format("YYYY-MM-DD");
286        }
287
288        var ajax_data = {
289          listing_type: $("#listing_type").val(),
290          listing_id: $("#listing_id").val(),
291          //'nonce': nonce
292        };
293        var invalid = false;
294        if (startDataSql) ajax_data.date_start = startDataSql;
295        if (endDataSql) ajax_data.date_end = endDataSql;
296        if ($("input#slot").val()) ajax_data.slot = $("input#slot").val();
297        if ($(".time-picker#_hour").val())
298          ajax_data._hour = $(".time-picker#_hour").val();
299        if ($(".time-picker#_hour_end").val())
300          ajax_data._hour_end = $(".time-picker#_hour_end").val();
301        if ($(".adults").val()) ajax_data.adults = $(".adults").val();
302        if ($("input[name=childrenQtyInput]").val()) ajax_data.children = $("input[name=childrenQtyInput]").val();
303        if ($("input[name=infantsQtyInput]").val()) ajax_data.infants = $("input[name=infantsQtyInput]").val();
304        if ($("input[name=animalsQtyInput]").val()) ajax_data.animals = $("input[name=animalsQtyInput]").val();
305        if ($("#tickets").val()) ajax_data.tickets = $("#tickets").val();
306        if ($("#coupon_code").val()) ajax_data.coupon = $("#coupon_code").val();
307
308        if ($("#listing_type").val() == "service") {
309          if (
310            $("input#slot").val() == undefined ||
311            $("input#slot").val() == ""
312          ) {
313            inputClicked = false;
314            invalid = true;
315          }
316          if ($(".time-picker").length) {
317            invalid = false;
318          }
319        }
320
321        if (invalid == false) {
322          var services = [];
323          // $.each($("input[name='_service[]']:checked"), function(){
324          //           		services.push($(this).val());
325          //       		});
326          $.each($("input.bookable-service-checkbox:checked"), function () {
327            var quantity = $(this)
328              .parent()
329              .find("input.bookable-service-quantity")
330              .val();
331            services.push({ service: $(this).val(), value: quantity });
332          });
333          ajax_data.services = services;
334          $("input#booking").val(JSON.stringify(ajax_data));
335       
336          $("#form-booking").submit();
337        }
338      }
339    } catch (e) {
340      console.log(e);
341    }
342
343    if ($("#listing_type").val() == "event") {
344      var ajax_data = {
345        listing_type: $("#listing_type").val(),
346        listing_id: $("#listing_id").val(),
347        date_start: $(".booking-event-date span").html(),
348        date_end: $(".booking-event-date span").html(),
349        //'nonce': nonce
350      };
351      if ($("#coupon_code").val()) ajax_data.coupon = $("#coupon_code").val();
352      var services = [];
353      $.each($("input.bookable-service-checkbox:checked"), function () {
354        var quantity = $(this)
355          .parent()
356          .find("input.bookable-service-quantity")
357          .val();
358        services.push({ service: $(this).val(), value: quantity });
359      });
360      ajax_data.services = services;
361
362      // converent data
363      ajax_data["date_start"] = moment(
364        ajax_data["date_start"],
365        wordpress_date_format.date
366      ).format("YYYY-MM-DD");
367      ajax_data["date_end"] = moment(
368        ajax_data["date_end"],
369        wordpress_date_format.date
370      ).format("YYYY-MM-DD");
371      if ($("#tickets").val()) ajax_data.tickets = $("#tickets").val();
372      $("input#booking").val(JSON.stringify(ajax_data));
373
374      $("#form-booking").submit();
375    }
376  });
377
378  if (Boolean(listeo_core.clockformat)) {
379    var dateformat_even = wordpress_date_format.date + " HH:mm";
380  } else {
381    var dateformat_even = wordpress_date_format.date + " hh:mm A";
382  }
383
384  function updateCounter() {
385    var len = $(".bookable-services input[type='checkbox']:checked").length;
386    if (len > 0) {
387      $(".booking-services span.services-counter").text("" + len + "");
388      $(".booking-services span.services-counter").addClass("counter-visible");
389    } else {
390      $(".booking-services span.services-counter").removeClass(
391        "counter-visible"
392      );
393      $(".booking-services span.services-counter").text("0");
394    }
395  }
396
397  $(".single-service").on("click", function () {
398    updateCounter();
399    $(".booking-services span.services-counter").addClass("rotate-x");
400
401    setTimeout(function () {
402      $(".booking-services span.services-counter").removeClass("rotate-x");
403    }, 300);
404  });
405
406  // $( ".input-datetime" ).each(function( index ) {
407  // 	var $this = $(this);
408  // 	var input = $(this).next('input');
409  //   	var date =  parseInt(input.val());
410  //   	if(date){
411  // 	  	var a = new Date(date);
412  // 		var timestamp = moment(a);
413  // 		$this.val(timestamp.format(dateformat_even));
414  //   	}
415
416  // });
417
418  //$('#_event_date').val(timestamp.format(dateformat_even));
419
420  // there are two fields with id _event_date and _event_date_end, make sure the event_date_end is not before event_date
421  // $('#_event_date_end').on('change', function() {
422  // 	alert('test');
423  // 	var start_date = $('#_event_date').val();
424  // 	var end_date = $('#_event_date_end').val();
425  // 	if(end_date < start_date){
426  // 		$('#_event_date_end').val(start_date);
427  // 	}
428  // });
429window.initializeDateRangePicker = function ($context = $(document)) {
430  $context.find(".input-datetime").each(function () {
431    // Prevent double init
432    if (!$(this).data("daterangepicker")) {
433      $(this).daterangepicker({
434        opens: "left",
435        singleDatePicker: true,
436        timePicker: true,
437        autoUpdateInput: false,
438        timePicker24Hour: Boolean(listeo_core.clockformat),
439        minDate: moment().subtract(0, "days"),
440        locale: {
441          format: dateformat_even,
442          firstDay: parseInt(wordpress_date_format.day),
443          applyLabel: listeo_core.applyLabel,
444          cancelLabel: listeo_core.cancelLabel,
445          fromLabel: listeo_core.fromLabel,
446          toLabel: listeo_core.toLabel,
447          customRangeLabel: listeo_core.customRangeLabel,
448          daysOfWeek: [
449            listeo_core.day_short_su,
450            listeo_core.day_short_mo,
451            listeo_core.day_short_tu,
452            listeo_core.day_short_we,
453            listeo_core.day_short_th,
454            listeo_core.day_short_fr,
455            listeo_core.day_short_sa,
456          ],
457          monthNames: [
458            listeo_core.january,
459            listeo_core.february,
460            listeo_core.march,
461            listeo_core.april,
462            listeo_core.may,
463            listeo_core.june,
464            listeo_core.july,
465            listeo_core.august,
466            listeo_core.september,
467            listeo_core.october,
468            listeo_core.november,
469            listeo_core.december,
470          ],
471        },
472      });
473    }
474  });
475};
476initializeDateRangePicker();
477
478  $(".input-datetime").on("apply.daterangepicker", function (ev, picker) {
479    $(this).val(picker.startDate.format(dateformat_even));
480    var end_date = $("#_event_date_end").length;
481    if (end_date) {
482      $(".input-datetime#_event_date_end")
483        .data("daterangepicker")
484        .setMinDate(picker.startDate.format(dateformat_even));
485    }
486  });
487
488  $(".input-datetime").on("cancel.daterangepicker", function (ev, picker) {
489    $(this).val("");
490  });
491
492  $(".input-date").daterangepicker({
493    opens: "left",
494    // checking attribute listing type and set type of calendar
495    singleDatePicker: true,
496    timePicker: false,
497    autoUpdateInput: false,
498
499    minDate: moment().subtract(0, "days"),
500
501    locale: {
502      format: dateformat_even,
503      firstDay: parseInt(wordpress_date_format.day),
504      applyLabel: listeo_core.applyLabel,
505      cancelLabel: listeo_core.cancelLabel,
506      fromLabel: listeo_core.fromLabel,
507      toLabel: listeo_core.toLabel,
508      customRangeLabel: listeo_core.customRangeLabel,
509      daysOfWeek: [
510        listeo_core.day_short_su,
511        listeo_core.day_short_mo,
512        listeo_core.day_short_tu,
513        listeo_core.day_short_we,
514        listeo_core.day_short_th,
515        listeo_core.day_short_fr,
516        listeo_core.day_short_sa,
517      ],
518      monthNames: [
519        listeo_core.january,
520        listeo_core.february,
521        listeo_core.march,
522        listeo_core.april,
523        listeo_core.may,
524        listeo_core.june,
525        listeo_core.july,
526        listeo_core.august,
527        listeo_core.september,
528        listeo_core.october,
529        listeo_core.november,
530        listeo_core.december,
531      ],
532    },
533  });
534
535  $(".input-date").on("apply.daterangepicker", function (ev, picker) {
536    $(this).val(picker.startDate.format("YYYY-MM-DD"));
537  });
538
539  $(".input-date").on("cancel.daterangepicker", function (ev, picker) {
540    $(this).val("");
541  });
542  // $('.input-datetime').on( 'apply.daterangepicker', function(){
543
544  // 	var picked_date = $(this).val();
545  // 	var input = $(this).next('input');
546  // 	input.val(moment(picked_date,dateformat_even).format('YYYY-MM-DD HH:MM:SS'));
547  // } );
548
549  function wpkGetThisDateSlots(date) {
550    var slots = {
551      isFirstSlotTaken: false,
552      isSecondSlotTaken: false,
553    };
554
555    if ($("#listing_type").val() == "event") return slots;
556
557    var dateString = date.format("YYYY-MM-DD");
558
559    // Check disabled dates first
560    if (typeof disabledDates !== "undefined") {
561      if (wpkIsDateInArray(date, disabledDates)) {
562        slots.isFirstSlotTaken = slots.isSecondSlotTaken = true;
563        console.log("Date " + dateString + " is in disabled dates");
564        return slots;
565      }
566    }
567
568    // Check booking dates
569    if (typeof wpkStartDates != "undefined" && typeof wpkEndDates != "undefined") {
570      slots.isSecondSlotTaken = wpkIsDateInArray(date, wpkStartDates);
571      slots.isFirstSlotTaken = wpkIsDateInArray(date, wpkEndDates);
572      
573      // Debug logging
574      console.log("Checking date: " + dateString);
575      console.log("Start dates check:", slots.isSecondSlotTaken);
576      console.log("End dates check:", slots.isFirstSlotTaken);
577      console.log("Both slots taken:", slots.isFirstSlotTaken && slots.isSecondSlotTaken);
578    }
579
580    return slots;
581  }
582
583  function wpkIsDateInArray(date, array) {
584    var dateString = date.format("YYYY-MM-DD");
585    var isInArray = false;
586    
587    // Check if array is object (with numeric keys) or regular array
588    if (Array.isArray(array)) {
589      isInArray = array.indexOf(dateString) !== -1;
590    } else if (typeof array === 'object') {
591      // Convert object values to array and check
592      var arrayValues = Object.values(array);
593      isInArray = arrayValues.indexOf(dateString) !== -1;
594    }
595    
596    console.log("Checking if " + dateString + " is in array:", isInArray);
597    return isInArray;
598  }
599
600  let startDate = Cookies.get("listeo_rental_startdate");
601  let endDate = Cookies.get("listeo_rental_enddate");
602  let minSpan = $("#date-picker").data("minspan");
603  let maxSpan = $("#date-picker").data("maxspan");
604  let availableHours = [];
605  var is24Hour = Boolean(listeo_core.clockformat);
606  var timePickerIncrement = $("#date-picker").data("time-increment");
607  //format: "M/DD hh:mm A";
608
609  // if startDate exist and is not empty, set autoUpdateInput to true
610  let autoUpdateInput = true;
611  if(startDate === undefined) {
612    autoUpdateInput = false;
613  }
614
615  // Update the daterangepicker options to properly handle blocked dates
616  let daterangepicker_options = {
617    opens: "left",
618    autoUpdateInput: autoUpdateInput,
619    singleDatePicker: $("#date-picker").data("listing_type") == "rental" ? false : true,
620    timePicker: $("#date-picker").data("rental-timepicker") == true ? true : false,
621    minDate: moment().subtract(0, "days"),
622    timePicker24Hour: is24Hour,
623    timePickerIncrement: timePickerIncrement,
624    minSpan: { days: minSpan },
625    startDate: startDate ? startDate : moment(),
626    endDate: endDate ? endDate : moment().add(minSpan, "days"),
627    locale: {
628      format: $("#date-picker").data("rental-timepicker") == true
629        ? wordpress_date_format.date + " hh:mm A"
630        : wordpress_date_format.date,
631      firstDay: parseInt(wordpress_date_format.day),
632      applyLabel: listeo_core.applyLabel,
633      cancelLabel: listeo_core.cancelLabel,
634      fromLabel: listeo_core.fromLabel,
635      toLabel: listeo_core.toLabel,
636      customRangeLabel: listeo_core.customRangeLabel,
637      daysOfWeek: [
638        listeo_core.day_short_su,
639        listeo_core.day_short_mo,
640        listeo_core.day_short_tu,
641        listeo_core.day_short_we,
642        listeo_core.day_short_th,
643        listeo_core.day_short_fr,
644        listeo_core.day_short_sa,
645      ],
646      monthNames: [
647        listeo_core.january,
648        listeo_core.february,
649        listeo_core.march,
650        listeo_core.april,
651        listeo_core.may,
652        listeo_core.june,
653        listeo_core.july,
654        listeo_core.august,
655        listeo_core.september,
656        listeo_core.october,
657        listeo_core.november,
658        listeo_core.december,
659      ],
660    },
661
662    isCustomDate: function (date) {
663      if ($("#date-picker").data("rental-timepicker") == true) {
664        var dateString = date.format("YYYY-MM-DD");
665
666        if (partialBookedDates && partialBookedDates[dateString]) {
667          var isFullyBooked = isDateFullyBooked(partialBookedDates[dateString]);
668          if (isFullyBooked) {
669            return "fully-booked";
670          }
671          return "partially-booked";
672        }
673
674        return "available";
675      } else {
676        var slots = wpkGetThisDateSlots(date);
677    
678        if (!slots.isFirstSlotTaken && !slots.isSecondSlotTaken) return [];
679
680        if (slots.isFirstSlotTaken && !slots.isSecondSlotTaken) {
681          return ["first-slot-taken"];
682        }
683
684        if (slots.isSecondSlotTaken && !slots.isFirstSlotTaken) {
685          return ["second-slot-taken"];
686        }
687
688        // If both slots are taken, return fully booked class
689        if (slots.isFirstSlotTaken && slots.isSecondSlotTaken) {
690          return ["fully-booked"];
691        }
692      }
693    },
694
695    isInvalidDate: function (date) {
696      // For events, don't block any dates
697      if ($("#listing_type").val() == "event") return false;
698      
699      // For services with disabled dates
700      if ($("#listing_type").val() == "service" && typeof disabledDates !== "undefined") {
701        if (jQuery.inArray(date.format("YYYY-MM-DD"), disabledDates) !== -1) {
702          return true;
703        }
704      }
705
706      // Handle time slots for services
707      if ($(".time-slots-dropdown").length) {
708        var timeslotdays = $(".time-slots-dropdown").data("slots-days").toString();
709        var timeslotdaysArray = timeslotdays.split(",");
710        
711        if (timeslotdaysArray.includes(moment(date).day().toString())) {
712          return false;
713        } else {
714          return true;
715        }
716      }
717
718      // For rental listings
719      if ($("#listing_type").val() == "rental") {
720        if ($("#date-picker").data("rental-timepicker") == true) {
721          var dateString = date.format("YYYY-MM-DD");
722
723          // Check disabled dates
724          if (typeof disabledDates !== "undefined" && disabledDates.indexOf(dateString) > -1) {
725            return true;
726          }
727
728          return false;
729        } else {
730          // Use the wpkGetThisDateSlots function to determine if date should be blocked
731          var slots = wpkGetThisDateSlots(date);
732          
733          // Block dates where both slots are taken (fully booked)
734          return slots.isFirstSlotTaken && slots.isSecondSlotTaken;
735        }
736      }
737
738      return false;
739    },
740  };
741
742  $("#date-picker").daterangepicker(daterangepicker_options);
743
744  $("#date-picker").on("show.daterangepicker", function (ev, picker) {
745    $(".daterangepicker").addClass("calendar-visible calendar-animated");
746    $(".daterangepicker").removeClass("calendar-hidden");
747  });
748  $("#date-picker").on("hide.daterangepicker", function (ev, picker) {
749    $(".daterangepicker").removeClass("calendar-visible");
750    $(".daterangepicker").addClass("calendar-hidden");
751  });
752
753  // Handle date/time selection
754  $(".date-picker-listing-rental").on(
755    "showCalendar.daterangepicker",
756    function (ev, picker) {
757      // Force update time picker whenever calendar is shown
758      if ($("#date-picker").data("rental-timepicker") == true) {
759        setTimeout(function () {
760          updateTimePicker(picker);
761        }, 50);
762      }
763    }
764  );
765
766  // Handle time picker changes
767  $(".date-picker-listing-rental").on(
768    "show.daterangepicker",
769    function (ev, picker) {
770      if ($("#date-picker").data("rental-timepicker") == true) {
771        // Initial time picker update
772        updateTimePicker(picker);
773
774        // Monitor for any changes to the time pickers
775        $(picker.container)
776          .find(".calendar-time")
777          .on("mousedown", function () {
778            //   setTimeout(function () {
779            updateTimePicker(picker);
780            // }, 50);
781          });
782      }
783    }
784  );
785
786  $(".date-picker-listing-rental").on(
787    "show.daterangepicker",
788    function (ev, picker) {
789      if ($("#date-picker").data("rental-timepicker") == true) {
790        setTimeout(function () {
791          // Add labels to calendar times if they don't exist
792          picker.container.find(".calendar-time").each(function (index) {
793            var $timeContainer = $(this);
794            if (!$timeContainer.prev().hasClass("calendar-time-label")) {
795              var label =
796                index === 0
797                  ? listeo_core.start_time_label
798                  : listeo_core.end_time_label;
799              $timeContainer.before(
800                '<div class="calendar-time-label">' + label + "</div>"
801              );
802            }
803          });
804
805          // Wrap selects in custom wrapper
806        }, 0);
807      }
808    }
809  );
810
811  function updateTimePicker(picker) {
812    var startDate = picker.startDate.format("YYYY-MM-DD");
813    var endDate = picker.endDate.format("YYYY-MM-DD");
814
815    // Get available times for start and end dates
816    var startTimes = getAvailableTimes(
817      startDate,
818      partialBookedDates[startDate],
819      "check-in"
820    );
821    var endTimes = getAvailableTimes(
822      endDate,
823      partialBookedDates[endDate],
824      "check-out"
825    );
826
827    // Get the time selectors for both start and end
828    var startContainer = $(picker.container).find(".calendar-time").first();
829    var endContainer = $(picker.container).find(".calendar-time").last();
830
831    // Update start time selectors
832    updateTimeSelectors(startContainer, startTimes, picker.startDate);
833
834    // Update end time selectors
835    updateTimeSelectors(endContainer, endTimes, picker.endDate);
836  }
837
838  function updateTimeSelectors(container, availableTimes, currentDate) {
839    var hourSelect = container.find(".hourselect");
840    var minuteSelect = container.find(".minuteselect");
841
842    // Get unique available hours
843    var availableHours = [
844      ...new Set(availableTimes.map((time) => parseInt(time.split(":")[0]))),
845    ].sort((a, b) => a - b);
846
847    // Clear and populate hour select
848    hourSelect.empty();
849    availableHours.forEach((hour) => {
850      hourSelect.append(
851        $("<option>", {
852          value: hour,
853          text: ("0" + hour).slice(-2),
854        })
855      );
856    });
857
858    // If current hour is not in available hours, select first available
859    var currentHour = currentDate.hour();
860    if (!availableHours.includes(currentHour)) {
861      hourSelect.val(availableHours[0]);
862      currentDate.hour(availableHours[0]);
863    } else {
864      hourSelect.val(currentHour);
865    }
866
867    // Update minutes for selected hour
868    updateMinutes(hourSelect, minuteSelect, availableTimes, currentDate);
869
870    // Add change handler for hours
871    hourSelect.off("change").on("change", function () {
872      updateMinutes(hourSelect, minuteSelect, availableTimes, currentDate);
873    });
874  }
875
876  function updateMinutes(
877    hourSelect,
878    minuteSelect,
879    availableTimes,
880    currentDate
881  ) {
882    var selectedHour = parseInt(hourSelect.val());
883
884    // Get available minutes for selected hour
885    var availableMinutes = availableTimes
886      .filter((time) => parseInt(time.split(":")[0]) === selectedHour)
887      .map((time) => parseInt(time.split(":")[1]))
888      .sort((a, b) => a - b);
889
890    // Clear and populate minute select
891    minuteSelect.empty();
892    availableMinutes.forEach((minute) => {
893      minuteSelect.append(
894        $("<option>", {
895          value: minute,
896          text: ("0" + minute).slice(-2),
897        })
898      );
899    });
900
901    // If current minute is not in available minutes, select first available
902    var currentMinute = currentDate.minute();
903    if (!availableMinutes.includes(currentMinute)) {
904      minuteSelect.val(availableMinutes[0]);
905      currentDate.minute(availableMinutes[0]);
906    } else {
907      minuteSelect.val(currentMinute);
908    }
909  }
910
911  function getAvailableTimes(date, bookedTimes, type) {
912    var times = [];
913    var startHour = type === "check-in" ? 7 : 10; // Check-in starts at 9 AM
914    var endHour = type === "check-out" ? 20 : 17; // Check-out until 5 PM
915
916    // Generate times in 15-minute increments
917    for (var hour = startHour; hour <= endHour; hour++) {
918      for (var minute = 0; minute < 60; minute += timePickerIncrement) {
919        var timeStr = ("0" + hour).slice(-2) + ":" + ("0" + minute).slice(-2);
920        if (!isTimeBooked(timeStr, bookedTimes)) {
921          times.push(timeStr);
922        }
923      }
924    }
925
926    return times;
927  }
928
929  function isTimeBooked(timeStr, bookedTimes) {
930    if (!bookedTimes) return false;
931
932    return bookedTimes.some(function (booking) {
933      return (
934        timeToMinutes(timeStr) >= timeToMinutes(booking.start) &&
935        timeToMinutes(timeStr) <= timeToMinutes(booking.end)
936      );
937    });
938  }
939
940  function isDateFullyBooked(bookings) {
941    var timeBlocks = mergeTimeBlocks(bookings);
942    return timeBlocks.some(function (block) {
943      return block.start === "00:00" && block.end === "23:59";
944    });
945  }
946
947  function mergeTimeBlocks(bookings) {
948    if (!bookings || !bookings.length) return [];
949
950    var sorted = bookings.sort(function (a, b) {
951      return a.start.localeCompare(b.start);
952    });
953
954    var merged = [];
955    var current = sorted[0];
956
957    for (var i = 1; i < sorted.length; i++) {
958      if (timeToMinutes(current.end) >= timeToMinutes(sorted[i].start)) {
959        if (timeToMinutes(sorted[i].end) > timeToMinutes(current.end)) {
960          current.end = sorted[i].end;
961        }
962      } else {
963        merged.push(current);
964        current = sorted[i];
965      }
966    }
967    merged.push(current);
968
969    return merged;
970  }
971
972  function timeToMinutes(timeStr) {
973    var parts = timeStr.split(":");
974    return parseInt(parts[0]) * 60 + parseInt(parts[1]);
975  }
976
977  $(".date-picker-listing-rental").on(
978    "apply.daterangepicker",
979    function (ev, picker) {
980      if ($("#date-picker").data("rental-timepicker") == true) {
981        if (picker.startDate && picker.endDate) {
982          var timeFormat = is24Hour ? "HH:mm" : "hh:mm A";
983          var startFormatted =
984            picker.startDate.format(wordpress_date_format.date) +
985            " " +
986            picker.startDate.format(timeFormat);
987          var endFormatted =
988            picker.endDate.format(wordpress_date_format.date) +
989            " " +
990            picker.endDate.format(timeFormat);
991          $(this).val(startFormatted + " - " + endFormatted);
992        }
993      } else {
994        $(this).val(
995          picker.startDate.format(wordpress_date_format.date) +
996            " - " +
997            picker.endDate.format(wordpress_date_format.date)
998        );
999      }
1000      // if it's other listing type, set date format 
1001    }
1002  );
1003
1004  $(".date-picker-listing-service").on(
1005    "apply.daterangepicker",
1006    function (ev, picker) {
1007      // For services we typically want just the selected date
1008      $(this).val(picker.startDate.format(wordpress_date_format.date));
1009
1010   
1011    }
1012  );
1013
1014  function updateTimePicker(picker) {
1015    var startDate = picker.startDate.format("YYYY-MM-DD");
1016    var endDate = picker.endDate.format("YYYY-MM-DD");
1017
1018    var startTimes = getAvailableTimes(
1019      startDate,
1020      partialBookedDates[startDate],
1021      "check-in"
1022    );
1023    var endTimes = getAvailableTimes(
1024      endDate,
1025      partialBookedDates[endDate],
1026      "check-out"
1027    );
1028
1029    var startContainer = $(picker.container).find(".calendar-time").first();
1030    var endContainer = $(picker.container).find(".calendar-time").last();
1031
1032    updateTimeSelectors(startContainer, startTimes, picker.startDate);
1033    updateTimeSelectors(endContainer, endTimes, picker.endDate);
1034  }
1035
1036  function updateTimeSelectors(container, availableTimes, currentDate) {
1037    var is24Hour = Boolean(listeo_core.clockformat);
1038    var hourSelect = container.find(".hourselect");
1039    var minuteSelect = container.find(".minuteselect");
1040    var ampmSelect = container.find(".ampmselect");
1041
1042    // Get current state
1043    var currentHour24 = currentDate.hour();
1044    var currentMinute = currentDate.minute();
1045    var isPM = currentHour24 >= 12;
1046
1047    function updateHourOptions() {
1048      var availableHours24 = [
1049        ...new Set(availableTimes.map((time) => parseInt(time.split(":")[0]))),
1050      ].sort((a, b) => a - b);
1051
1052      // Filter hours based on AM/PM if in 12-hour mode
1053      if (!is24Hour) {
1054        var selectedIsPM = ampmSelect.val() === "PM";
1055        availableHours24 = availableHours24.filter((hour) => {
1056          return selectedIsPM ? hour >= 12 : hour < 12;
1057        });
1058      }
1059
1060      hourSelect.empty();
1061      availableHours24.forEach((hour24) => {
1062        var displayHour = is24Hour ? hour24 : hour24 % 12 || 12;
1063        hourSelect.append(
1064          $("<option>", {
1065            value: hour24, // Store 24-hour value
1066            text: ("0" + displayHour).slice(-2),
1067          })
1068        );
1069      });
1070
1071      // Set appropriate hour
1072      if (availableHours24.length > 0) {
1073        var currentHourExists = availableHours24.includes(currentHour24);
1074        var hourToSet = currentHourExists ? currentHour24 : availableHours24[0];
1075        hourSelect.val(hourToSet);
1076        currentDate.hour(hourToSet);
1077        return hourToSet;
1078      }
1079      return null;
1080    }
1081
1082    // Initial hour update
1083    var selectedHour24 = updateHourOptions();
1084
1085    // Update minutes for the selected hour
1086    function updateMinutes(hour24) {
1087      if (hour24 === null) return;
1088
1089      var availableMinutes = availableTimes
1090        .filter((time) => parseInt(time.split(":")[0]) === hour24)
1091        .map((time) => parseInt(time.split(":")[1]))
1092        .sort((a, b) => a - b);
1093
1094      minuteSelect.empty();
1095      availableMinutes.forEach((minute) => {
1096        minuteSelect.append(
1097          $("<option>", {
1098            value: minute,
1099            text: ("0" + minute).slice(-2),
1100          })
1101        );
1102      });
1103
1104      // Set appropriate minute
1105      if (availableMinutes.length > 0) {
1106        if (availableMinutes.includes(currentMinute)) {
1107          minuteSelect.val(currentMinute);
1108        } else {
1109          minuteSelect.val(availableMinutes[0]);
1110          currentDate.minute(availableMinutes[0]);
1111        }
1112      }
1113    }
1114
1115    updateMinutes(selectedHour24);
1116
1117    // Event handlers
1118    if (!is24Hour) {
1119      ampmSelect.off("change").on("change", function () {
1120        var newHour24 = updateHourOptions();
1121        updateMinutes(newHour24);
1122      });
1123    }
1124
1125    hourSelect.off("change").on("change", function () {
1126      var selectedHour24 = parseInt($(this).val());
1127      currentDate.hour(selectedHour24);
1128      updateMinutes(selectedHour24);
1129    });
1130
1131    minuteSelect.off("change").on("change", function () {
1132      currentDate.minute(parseInt($(this).val()));
1133    });
1134
1135    // Set initial AM/PM if in 12-hour mode
1136    if (!is24Hour) {
1137      ampmSelect.val(isPM ? "PM" : "AM");
1138    }
1139  }
1140
1141  // Utility functions remain the same...
1142  function getAvailableTimes(date, bookedTimes, type) {
1143    var times = [];
1144    //if availableDays is not set, return empty array
1145    console.log(availableDays);
1146    if (
1147      typeof availableDays === "undefined" ||
1148      availableDays === null ||
1149      availableDays === ""
1150    ) {
1151      var listingOpeningHours = [];
1152    } else {
1153      var listingOpeningHours = JSON.parse(availableDays);
1154    }
1155
1156    // Get day of week from the date (0 = Monday, 6 = Sunday)
1157    // var dayIndex = moment(date).day();
1158    // dayIndex = dayIndex === 0 ? 6 : dayIndex - 1;
1159    var dayOfWeek = moment(date).isoWeekday(); // Returns 1-7 (Monday-Sunday)
1160
1161    // Get opening hours for this day
1162    var dayIndex = dayOfWeek - 1;
1163    // Get opening hours for this day
1164    var dayHours = listingOpeningHours[dayIndex];
1165    console.log(dayHours);
1166    // If no hours set for this day or empty values, use default full day availability
1167    if (
1168      !dayHours ||
1169      !dayHours.opening ||
1170      !dayHours.closing ||
1171      dayHours.opening[0] === "" ||
1172      dayHours.closing[0] === ""
1173    ) {
1174      // Use default hours based on check-in/check-out type
1175      // var defaultHours = {
1176      //     opening: [(type === 'check-in' ? "09:00" : "10:00")],
1177      //     closing: [(type === 'check-out' ? "20:00" : "17:00")]
1178      // };
1179
1180      //dayHours = defaultHours;
1181      dayHours = {
1182        opening: ["00:00"],
1183        closing: ["23:59"],
1184      };
1185    }
1186
1187    // Process each set of opening/closing hours
1188    for (var i = 0; i < dayHours.opening.length; i++) {
1189      var openTime = dayHours.opening[i];
1190      var closeTime = dayHours.closing[i];
1191
1192      if (!openTime || !closeTime) continue;
1193
1194      // Convert opening/closing times to hours and minutes
1195      var openHour = parseInt(openTime.split(":")[0]);
1196      var closeHour = parseInt(closeTime.split(":")[0]);
1197      var openMinute = parseInt(openTime.split(":")[1]);
1198      var closeMinute = parseInt(closeTime.split(":")[1]);
1199
1200      // // Apply check-in/check-out restrictions
1201      // if (type === 'check-in') {
1202      //     // Don't allow check-in less than 1 hour before closing
1203      //     var closeTimeInMinutes = closeHour * 60 + closeMinute;
1204      //     closeTimeInMinutes -= 60; // Subtract 1 hour
1205      //     closeHour = Math.floor(closeTimeInMinutes / 60);
1206      //     closeMinute = closeTimeInMinutes % 60;
1207      // } else { // check-out
1208      //     // Don't allow check-out before 10 AM or after 5 PM
1209      //     if (openHour < 10) {
1210      //         openHour = 10;
1211      //         openMinute = 0;
1212      //     }
1213      //     if (closeHour > 17 || (closeHour === 17 && closeMinute > 0)) {
1214      //         closeHour = 17;
1215      //         closeMinute = 0;
1216      //     }
1217      // }
1218
1219      // Generate available times within the valid range
1220      var currentHour = openHour;
1221      var currentMinute =
1222        currentHour === openHour
1223          ? Math.ceil(openMinute / timePickerIncrement) * timePickerIncrement
1224          : 0;
1225
1226      var endTimeInMinutes = closeHour * 60 + closeMinute;
1227
1228      while (currentHour * 60 + currentMinute <= endTimeInMinutes) {
1229        var timeStr =
1230          ("0" + currentHour).slice(-2) + ":" + ("0" + currentMinute).slice(-2);
1231
1232        if (!isTimeBooked(timeStr, bookedTimes)) {
1233          times.push(timeStr);
1234        }
1235
1236        currentMinute += timePickerIncrement;
1237        if (currentMinute >= 60) {
1238          currentMinute = 0;
1239          currentHour++;
1240        }
1241      }
1242    }
1243
1244    return times.sort();
1245  }
1246
1247  function isTimeBooked(timeStr, bookedTimes) {
1248    if (!bookedTimes) return false;
1249
1250    return bookedTimes.some(function (booking) {
1251      return (
1252        timeToMinutes(timeStr) >= timeToMinutes(booking.start) &&
1253        timeToMinutes(timeStr) <= timeToMinutes(booking.end)
1254      );
1255    });
1256  }
1257
1258  function timeToMinutes(timeStr) {
1259    var parts = timeStr.split(":");
1260    return parseInt(parts[0]) * 60 + parseInt(parts[1]);
1261  }
1262
1263  function updateSelectOptions($select, options) {
1264    // Clear existing options
1265    $select.empty();
1266
1267    // Add new options
1268    options.forEach(function (option) {
1269      $select.append(
1270        $("<option>", {
1271          value: option.value,
1272          text: option.text,
1273        })
1274      );
1275    });
1276
1277    // Refresh bootstrap-select
1278    $select.selectpicker("refresh");
1279  }
1280
1281  // $(".date-picker-listing-rental").on(
1282  //   "apply.daterangepicker",
1283  //   function (ev, picker) {
1284  //     var startDate = picker.startDate.format("YYYY-MM-DD");
1285  //     var endDate = picker.endDate.format("YYYY-MM-DD");
1286
1287  //     // Check if selected dates include any partial bookings
1288  //     var hasPartialBookings = false;
1289  //     var current = moment(startDate);
1290  //     var end = moment(endDate);
1291
1292  //     while (current <= end) {
1293  //       var dateString = current.format("YYYY-MM-DD");
1294  //       if (partialBookedDates && partialBookedDates[dateString]) {
1295  //         hasPartialBookings = true;
1296  //         break;
1297  //       }
1298  //       current.add(1, "days");
1299  //     }
1300
1301  //     if (hasPartialBookings) {
1302  //       // Show time selection dialog
1303  //       showTimeSelectionDialog(startDate, endDate, partialBookedDates);
1304  //     }
1305
1306  //     $(this).val(
1307  //       picker.startDate.format(listeo_core.date_format) +
1308  //         " - " +
1309  //         picker.endDate.format(listeo_core.date_format)
1310  //     );
1311  //   }
1312  // );
1313
1314  // $("#date-picker").on("apply.daterangepicker", function (ev, picker) {
1315  //   const listing_id = $("#listing_id").val();
1316  //   const startDate = picker.startDate.format("YYYY-MM-DD HH:mm:ss");
1317  //   const endDate = picker.endDate.format("YYYY-MM-DD HH:mm:ss");
1318  // 	$(".date-picker-listing-rental").removeClass("add-slot-shake-error");
1319  //   $.ajax({
1320  //     url: listeo.ajaxurl,
1321  //     type: "POST",
1322  //     data: {
1323  //       action: "check_date_range_availability",
1324  //       listing_id: listing_id,
1325  //       start_date: startDate,
1326  //       end_date: endDate,
1327  //     },
1328  //     success: function (response) {
1329  //       if (response.success) {
1330  //         if (response.data.available) {
1331  //           check_booking();
1332  //           // wait 2s and fadeOut .booking-notice-message
1333  // 		  setTimeout(function () {
1334  // 			$(".booking-notice-message").fadeOut();
1335  // 		  }, 2000);
1336  //         } else {
1337  //           if (response.data.next_available) {
1338  //             // Parse dates from response
1339  //             const newStartDate = moment(response.data.next_available.start);
1340  //             const newEndDate = moment(response.data.next_available.end);
1341  // 			$(".date-picker-listing-rental").addClass("add-slot-shake-error");
1342  //             $(".booking-notice-message")
1343  //               .html(
1344  //                 "Selected time is not available.\n\n" +
1345  //                   "Next available time is:\n" +
1346  //                   newStartDate.format("DD-MM-YYYY HH:mm") +
1347  //                   " to " +
1348  //                   newEndDate.format("DD-MM-YYYY HH:mm")
1349  //               )
1350  //               .fadeIn();
1351
1352  //             // Update the date picker with new dates
1353  //             picker.setStartDate(newStartDate);
1354  //             picker.setEndDate(newEndDate);
1355
1356  //             // Optional: Trigger the date picker to update its display
1357  //             $(picker.element).data("daterangepicker").updateView();
1358  //             $(picker.element).data("daterangepicker").updateCalendars();
1359  //           } else {
1360  //             alert(response.data.message || "No available time slots found.");
1361  //           }
1362  //         }
1363  //       }
1364  //     },
1365  //     error: function () {
1366  //       alert("There was an error checking availability. Please try again.");
1367  //     },
1368  //   });
1369  // });
1370
1371  //   // When time is selected
1372  //   $("#date-picker").on("apply.daterangepicker", function (ev, picker) {
1373  //     const selectedDateTime = picker.startDate;
1374  //     let isValidSelection = false;
1375
1376  //     if (availableHours && availableHours.length > 0) {
1377  //       for (let slot of availableHours) {
1378  //         const slotStart = moment(slot.start);
1379  //         const slotEnd = moment(slot.end);
1380
1381  //         if (selectedDateTime.isBetween(slotStart, slotEnd, undefined, "[]")) {
1382  //           isValidSelection = true;
1383  //           break;
1384  //         }
1385  //       }
1386
1387  //       if (!isValidSelection) {
1388  //         // Find first available time
1389  //         const firstSlot = availableHours[0];
1390  //         if (firstSlot) {
1391  //           picker.setStartDate(moment(firstSlot.start));
1392  //           alert(
1393  //             "Selected time is not available. Moving to first available time."
1394  //           );
1395  //         }
1396  //         return false;
1397  //       }
1398  //     }
1399
1400  //     // If we get here, proceed with booking check
1401  //     check_booking();
1402  //   });
1403  function calculate_price() {
1404    var ajax_data = {
1405      action: "calculate_price",
1406      listing_type: $("#date-picker").data("listing_type"),
1407      listing_id: $("input#listing_id").val(),
1408      tickets: $("input#tickets").val(),
1409      coupon: $("input#coupon_code").val(),
1410      //'nonce': nonce
1411    };
1412
1413    // Add children count if present
1414    if ($(".qtyButtons.children input").length) {
1415      ajax_data.children = $(".qtyButtons.children input").val();
1416    }
1417
1418    // Add pets count if present
1419    if ($(".qtyButtons.animals input").length) {
1420      ajax_data.animals = $(".qtyButtons.animals input").val();
1421    }
1422    var services = [];
1423
1424    $.each($("input.bookable-service-checkbox:checked"), function () {
1425      var quantity = $(this)
1426        .parent()
1427        .find("input.bookable-service-quantity")
1428        .val();
1429      services.push({ service: $(this).val(), value: quantity });
1430    });
1431    ajax_data.services = services;
1432    $.ajax({
1433      type: "POST",
1434      dataType: "json",
1435      url: listeo.ajaxurl,
1436      data: ajax_data,
1437
1438      success: function (data) {
1439        $("#negative-feedback").fadeOut();
1440        $("a.book-now").removeClass("inactive");
1441        if (data.data.price) {
1442          if (listeo_core.currency_position == "before") {
1443            $(".booking-estimated-cost span").html(
1444              listeo_core.currency_symbol + " " + data.data.price
1445            );
1446          } else {
1447            $(".booking-estimated-cost span").html(
1448              data.data.price + " " + listeo_core.currency_symbol
1449            );
1450          }
1451          $(".booking-estimated-cost").data("price", data.data.price);
1452          $(".booking-estimated-cost").fadeIn();
1453        }
1454        if (data.data.price_discount) {
1455          if (listeo_core.currency_position == "before") {
1456            $(".booking-estimated-discount-cost span").html(
1457              listeo_core.currency_symbol + " " + data.data.price_discount
1458            );
1459          } else {
1460            $(".booking-estimated-discount-cost span").html(
1461              data.data.price_discount + " " + listeo_core.currency_symbol
1462            );
1463          }
1464          $(".booking-estimated-cost").addClass("estimated-with-discount");
1465          $(".booking-estimated-discount-cost").fadeIn();
1466        } else {
1467          $(".booking-estimated-cost").removeClass("estimated-with-discount");
1468          $(".booking-estimated-discount-cost").fadeOut();
1469        }
1470      },
1471    });
1472  }
1473
1474  function calculate_booking_form_price() {
1475    var ajax_data = {
1476      action: "listeo_calculate_booking_form_price",
1477      coupon: $("input#coupon_code").val(),
1478      price: $("li.total-costs").data("price"),
1479    };
1480
1481    $.ajax({
1482      type: "POST",
1483      dataType: "json",
1484      url: listeo.ajaxurl,
1485      data: ajax_data,
1486
1487      success: function (data) {
1488        if (data.price >= 0) {
1489          if (listeo_core.currency_position == "before") {
1490            $(".total-discounted_costs span").html(
1491              listeo_core.currency_symbol + " " + data.price
1492            );
1493          } else {
1494            $(".total-discounted_costs span").html(
1495              data.price + " " + listeo_core.currency_symbol
1496            );
1497          }
1498
1499          $(".total-discounted_costs").fadeIn();
1500          $(".total-costs").addClass("estimated-with-discount");
1501        } else {
1502          $(".total-discounted_costs ").fadeOut();
1503          $(".total-costs").removeClass("estimated-with-discount");
1504        }
1505      },
1506    });
1507  }
1508
1509  // function when checking booking by widget
1510  function check_booking() {
1511    inputClicked = true;
1512    if (is_open === false) return 0;
1513
1514    // if we not deal with services with slots or opening hours
1515    if (
1516      $("#date-picker").data("listing_type") == "service" &&
1517      !$("input#slot").val() &&
1518      !$(".time-picker").val()
1519    ) {
1520      $("#negative-feedback").fadeIn();
1521
1522      return;
1523    }
1524
1525    if ($("#date-picker").data("rental-timepicker")) {
1526      Cookies.set(
1527        "listeo_rental_picker_startdate",
1528        $("#date-picker")
1529          .data("daterangepicker")
1530          .startDate.format(wordpress_date_format.date + " hh:mm A")
1531      );
1532      Cookies.set(
1533        "listeo_rental_picker_enddate",
1534        $("#date-picker")
1535          .data("daterangepicker")
1536          .endDate.format(wordpress_date_format.date + " hh:mm A")
1537      );
1538      // var startDataSQL need to have hour
1539      var startDataSql = moment(
1540        $("#date-picker").data("daterangepicker").startDate,
1541        ["MM/DD/YYYY hh:mm A"]
1542      ).format("YYYY-MM-DD HH:mm:ss");
1543      var endDataSql = moment(
1544        $("#date-picker").data("daterangepicker").endDate,
1545        ["MM/DD/YYYY hh:mm A"]
1546      ).format("YYYY-MM-DD HH:mm:ss");
1547    } else {
1548      Cookies.set(
1549        "listeo_rental_startdate",
1550        $("#date-picker")
1551          .data("daterangepicker")
1552          .startDate.format(wordpress_date_format.date)
1553      );
1554      Cookies.set(
1555        "listeo_rental_enddate",
1556        $("#date-picker")
1557          .data("daterangepicker")
1558          .endDate.format(wordpress_date_format.date)
1559      );
1560      var startDataSql = moment(
1561        $("#date-picker").data("daterangepicker").startDate,
1562        ["MM/DD/YYYY"]
1563      ).format("YYYY-MM-DD");
1564      var endDataSql = moment(
1565        $("#date-picker").data("daterangepicker").endDate,
1566        ["MM/DD/YYYY"]
1567      ).format("YYYY-MM-DD");
1568    }
1569
1570    //console.log($('#date-picker').data('daterangepicker').startDate);
1571
1572    // preparing data for ajax
1573    var ajax_data = {
1574      action: "check_avaliabity",
1575      listing_type: $("#date-picker").data("listing_type"),
1576      listing_id: $("input#listing_id").val(),
1577      coupon: $("input#coupon_code").val(),
1578      date_start: startDataSql,
1579      date_end: endDataSql,
1580      //'nonce': nonce
1581    };
1582    var services = [];
1583    // $.each($("input.bookable-service-checkbox:checked"), function(){
1584    //   		services.push($(this).val());
1585    // });
1586    // $.each($("input.bookable-service-quantity"), function(){
1587    //   		services.push($(this).val());
1588    // });
1589    $.each($("input.bookable-service-checkbox:checked"), function () {
1590      var quantity = $(this)
1591        .parent()
1592        .find("input.bookable-service-quantity")
1593        .val();
1594      services.push({ service: $(this).val(), value: quantity });
1595    });
1596
1597    ajax_data.services = services;
1598
1599    if ($("input#slot").val()) ajax_data.slot = $("input#slot").val();
1600    if ($("input.adults").val()) ajax_data.adults = $("input.adults").val();
1601
1602    if ($(".time-picker").val()) ajax_data.hour = $(".time-picker").val();
1603    if ($(".time-picker-end-hour").val())
1604      ajax_data.end_hour = $(".time-picker-end-hour").val();
1605
1606    // Add children count if present
1607    if ($(".qtyButtons input.children ").length) {
1608      ajax_data.children = $(".qtyButtons input.children ").val();
1609    }
1610
1611    // Add animals count if present
1612    if ($(".qtyButtons input.animals ").length) {
1613      ajax_data.animals = $(".qtyButtons input.animals").val();
1614    }
1615
1616    // loader class
1617    $("a.book-now").addClass("loading");
1618    $("a.book-now-notloggedin").addClass("loading");
1619
1620    $.ajax({
1621      type: "POST",
1622      dataType: "json",
1623      url: listeo.ajaxurl,
1624      data: ajax_data,
1625
1626      success: function (data) {
1627        // loader clas
1628        if (
1629          data.success == true &&
1630          (!$(".time-picker").length || is_open != false)
1631        ) {
1632          if (data.data.free_places > 0) {
1633            $("a.book-now,a.book-now-notloggedin").data(
1634              "freeplaces",
1635              data.data.free_places
1636            );
1637            // if date picker doesn't have daat attribute rental-timepicker
1638
1639            $(".booking-error-message").fadeOut();
1640            $("a.book-now").removeClass("inactive");
1641            if (data.data.price) {
1642              if (listeo_core.currency_position == "before") {
1643                $(".booking-estimated-cost span").html(
1644                  listeo_core.currency_symbol + " " + data.data.price
1645                );
1646              } else {
1647                $(".booking-estimated-cost span").html(
1648                  data.data.price + " " + listeo_core.currency_symbol
1649                );
1650              }
1651              $(".booking-estimated-cost").data("price", data.data.price);
1652              $(".booking-estimated-cost").fadeIn();
1653            } else {
1654              $(".booking-estimated-cost span").html(
1655                "0 " + listeo_core.currency_symbol
1656              );
1657              $(".booking-estimated-cost").fadeOut();
1658            }
1659            if (data.data.price_discount) {
1660              if (listeo_core.currency_position == "before") {
1661                $(".booking-estimated-discount-cost span").html(
1662                  listeo_core.currency_symbol + " " + data.data.price_discount
1663                );
1664              } else {
1665                $(".booking-estimated-discount-cost span").html(
1666                  data.data.price_discount + " " + listeo_core.currency_symbol
1667                );
1668              }
1669              $(".booking-estimated-cost").addClass("estimated-with-discount");
1670              $(".booking-estimated-discount-cost").fadeIn();
1671            } else {
1672              $(".booking-estimated-cost").removeClass(
1673                "estimated-with-discount"
1674              );
1675              $(".booking-estimated-discount-cost").fadeOut();
1676            }
1677            validate_coupon($("input#listing_id").val(), data.data.price);
1678            $(".coupon-widget-wrapper").fadeIn();
1679          } else {
1680            $("a.book-now,a.book-now-notloggedin").data("freeplaces", 0);
1681            // if (!$("#date-picker").data("rental-timepicker")) {
1682            //   $(".booking-error-message").fadeIn();
1683            // }
1684            $(".booking-error-message").fadeIn();
1685            $(".booking-estimated-cost").fadeOut();
1686
1687            $(".booking-estimated-cost span").html("");
1688          }
1689        } else {
1690          //   if (!$("#date-picker").data("rental-timepicker")) {
1691          //     $("a.book-now,a.book-now-notloggedin").data("freeplaces", 0);
1692          //     $(".booking-error-message").fadeIn();
1693          //   }
1694          $(".booking-error-message").fadeIn();
1695          $(".booking-estimated-cost").fadeOut();
1696        }
1697        $("a.book-now").removeClass("loading");
1698        $("a.book-now-notloggedin").removeClass("loading");
1699      },
1700    });
1701  }
1702
1703  var is_open = true;
1704  var lastDayOfWeek;
1705
1706  // update slots and check hours setted to this day
1707  function update_booking_widget() {
1708    // function only for services
1709    if ($("#date-picker").data("listing_type") != "service") return;
1710
1711    $("a.book-now").addClass("loading");
1712    $("a.book-now-notloggedin").addClass("loading");
1713    // get day of week
1714
1715    var date = $("#date-picker").data("daterangepicker").endDate._d;
1716    var dayOfWeek = date.getDay() - 1;
1717
1718    if (date.getDay() == 0) {
1719      dayOfWeek = 6;
1720    }
1721
1722    var startDataSql = moment(
1723      $("#date-picker").data("daterangepicker").startDate,
1724      ["MM/DD/YYYY"]
1725    ).format("YYYY-MM-DD");
1726    var endDataSql = moment($("#date-picker").data("daterangepicker").endDate, [
1727      "MM/DD/YYYY",
1728    ]).format("YYYY-MM-DD");
1729
1730    var ajax_data = {
1731      action: "update_slots",
1732      listing_id: $("input#listing_id").val(),
1733      date_start: startDataSql,
1734      date_end: endDataSql,
1735      slot: dayOfWeek,
1736      //'nonce': nonce
1737    };
1738
1739    $.ajax({
1740      type: "POST",
1741      dataType: "json",
1742      url: listeo.ajaxurl,
1743      data: ajax_data,
1744
1745      success: function (data) {
1746        $(".time-slots-dropdown .panel-dropdown-scrollable").html(data.data);
1747
1748        // reset values of slot selector
1749        if (dayOfWeek != lastDayOfWeek) {
1750          $(".panel-dropdown-scrollable .time-slot input").prop(
1751            "checked",
1752            false
1753          );
1754
1755          $(".panel-dropdown.time-slots-dropdown input#slot").val("");
1756          $(".panel-dropdown.time-slots-dropdown a").html(
1757            $(".panel-dropdown.time-slots-dropdown a").attr("placeholder")
1758          );
1759          $(" .booking-estimated-cost span").html(" ");
1760        }
1761
1762        lastDayOfWeek = dayOfWeek;
1763
1764        if (
1765          !$(".panel-dropdown-scrollable .time-slot[day='" + dayOfWeek + "']")
1766            .length
1767        ) {
1768          $(".no-slots-information").show();
1769          $(".panel-dropdown.time-slots-dropdown a").html(
1770            $(".no-slots-information").html()
1771          );
1772        } else {
1773          // when we dont have slots for this day reset cost and show no slots
1774          $(".no-slots-information").hide();
1775          $(".panel-dropdown.time-slots-dropdown a").html(
1776            $(".panel-dropdown.time-slots-dropdown a").attr("placeholder")
1777          );
1778          $(" .booking-estimated-cost span").html(" ");
1779        }
1780        // show only slots for this day
1781        $(".panel-dropdown-scrollable .time-slot").hide();
1782
1783        $(
1784          ".panel-dropdown-scrollable .time-slot[day='" + dayOfWeek + "']"
1785        ).show();
1786        $(".time-slot").each(function () {
1787          var timeSlot = $(this);
1788          $(this)
1789            .find("input")
1790            .on("change", function () {
1791              var timeSlotVal = timeSlot.find("strong").text();
1792              var slotArray = [
1793                timeSlot.find("strong").text(),
1794                timeSlot.find("input").val(),
1795              ];
1796
1797              $(".panel-dropdown.time-slots-dropdown input#slot").val(
1798                JSON.stringify(slotArray)
1799              );
1800
1801              $(".panel-dropdown.time-slots-dropdown a").html(timeSlotVal);
1802
1803              $(".panel-dropdown").removeClass("active");
1804
1805              check_booking();
1806            });
1807        });
1808        $("a.book-now").removeClass("loading");
1809        $("a.book-now-notloggedin").removeClass("loading");
1810      },
1811    });
1812
1813    // check if opening days are active
1814    if ($(".time-picker").length) {
1815      if (availableDays) {
1816        var availableDays = JSON.parse(availableDays);
1817
1818        if (
1819          availableDays[dayOfWeek].opening == "Closed" ||
1820          availableDays[dayOfWeek].closing == "Closed"
1821        ) {
1822          $("#negative-feedback").fadeIn();
1823
1824          //$('a.book-now').css('background-color','grey');
1825
1826          is_open = false;
1827          //console.log('zamkniete tego dnia' + dayOfWeek);
1828          return;
1829        }
1830
1831        // converent hours to 24h format
1832        var opening_hour = moment(availableDays[dayOfWeek].opening, [
1833          "h:mm A",
1834        ]).format("HH:mm");
1835        var closing_hour = moment(availableDays[dayOfWeek].closing, [
1836          "h:mm A",
1837        ]).format("HH:mm");
1838
1839        // get hour in 24 format
1840        var current_hour = $(".time-picker").val();
1841
1842        // check if currer hour bar is open
1843        if (current_hour >= opening_hour && current_hour <= closing_hour) {
1844          is_open = true;
1845          $("#negative-feedback").fadeOut();
1846          $("a.book-now").attr("href", "#").css("background-color", "#f30c0c");
1847          check_booking();
1848          //console.log('otwarte' + dayOfWeek);
1849        } else {
1850          is_open = false;
1851          $("#negative-feedback").fadeIn();
1852          //$('a.book-now').attr('href','#').css('background-color','grey');
1853          $(".booking-estimated-cost span").html("");
1854          //console.log('zamkniete');
1855        }
1856      } else {
1857        check_booking();
1858      }
1859    }
1860  }
1861
1862  // if slots exist update them
1863  if ($(".time-slot").length) {
1864    
1865    update_booking_widget();
1866  }
1867
1868  // show only services for actual day from datapicker
1869  $("#date-picker").on("apply.daterangepicker", update_booking_widget);
1870  $("#date-picker").on("change", function () {
1871    
1872    check_booking();
1873    //	update_booking_widget();
1874  });
1875
1876  // when slot is selected check if there are avalible bookings
1877  $("#date-picker").on("apply.daterangepicker", check_booking);
1878  $("#date-picker").on("cancel.daterangepicker", check_booking);
1879
1880  $(document).on(
1881    "change",
1882    "input#slot,input.adults,.panel-with-children input, input.bookable-service-quantity, .form-booking-service input.bookable-service-checkbox,.form-booking-rental input.bookable-service-checkbox",
1883    function (event) {
1884      check_booking();
1885    }
1886  );
1887  //$('input#slot').on( 'change', check_booking );
1888
1889  $("input#tickets,.form-booking-event input.bookable-service-checkbox").on(
1890    "change",
1891    function (e) {
1892      //check_booking();
1893      calculate_price();
1894    }
1895  );
1896
1897  // hours picker
1898  if ($(".time-picker").length) {
1899    var time24 = false;
1900
1901    if (listeo_core.clockformat) {
1902      time24 = true;
1903    }
1904    const calendars = $(".time-picker").flatpickr({
1905      enableTime: true,
1906      noCalendar: true,
1907      dateFormat: "H:i",
1908      time_24hr: time24,
1909      disableMobile: "true",
1910      minuteIncrement: timePickerIncrement,
1911
1912      // check if there are free days on change and calculate price
1913      onClose: function (selectedDates, dateStr, instance) {
1914        update_booking_widget();
1915        check_booking();
1916      },
1917    });
1918
1919    if ($("#_hour_end").length) {
1920      calendars[0].config.onClose = [
1921        () => {
1922          setTimeout(() => calendars[1].open(), 1);
1923        },
1924      ];
1925
1926      calendars[0].config.onChange = [
1927        (selDates) => {
1928          calendars[1].set("minDate", selDates[0]);
1929        },
1930      ];
1931      // 		 calendars[0].config.onChange = [
1932      //      (selDates) => {
1933      //        if (selDates[0]) {
1934      //          let minEndDate = new Date(selDates[0]);
1935      //          minEndDate.setHours(minEndDate.getHours() + 4);
1936      //          calendars[1].set("minDate", minEndDate);
1937      //        }
1938      //      },
1939      //    ];
1940
1941      calendars[1].config.onChange = [
1942        (selDates) => {
1943          calendars[0].set("maxDate", selDates[0]);
1944        },
1945      ];
1946    }
1947  }
1948
1949  /*----------------------------------------------------*/
1950  /*  Bookings Dashboard Script
1951/*----------------------------------------------------*/
1952  $(".booking-services").on("click", ".qtyInc", function () {
1953    var $button = $(this);
1954
1955    var oldValue = $button.parent().find("input").val();
1956    //console.log(oldValue);
1957    if (oldValue == 2) {
1958      //$button.parents('.single-service').find('label').trigger('click');
1959      $button
1960        .parents(".single-service")
1961        .find("input.bookable-service-checkbox")
1962        .prop("checked", true);
1963      updateCounter();
1964    }
1965    if ($("#form-booking").hasClass("form-booking-event")) {
1966      calculate_price();
1967    } else {
1968      check_booking();
1969    }
1970    //calculate_price();
1971  });
1972
1973  if ($("#booking-date-range").length) {
1974    // to update view with bookin
1975
1976    var bookingsOffset = 0;
1977
1978    // here we can set how many bookings per page
1979    var bookingsLimit = 5;
1980
1981    // function when checking booking by widget
1982    function listeo_bookings_manage(page) {
1983      if ($("#booking-date-range").data("daterangepicker")) {
1984        var startDataSql = moment(
1985          $("#booking-date-range").data("daterangepicker").startDate,
1986          ["MM/DD/YYYY"]
1987        ).format("YYYY-MM-DD");
1988        var endDataSql = moment(
1989          $("#booking-date-range").data("daterangepicker").endDate,
1990          ["MM/DD/YYYY"]
1991        ).format("YYYY-MM-DD");
1992      } else {
1993        var startDataSql = "";
1994        var endDataSql = "";
1995      }
1996      if (!page) {
1997        page = 1;
1998      }
1999      if (page == "prev") {
2000        var current = $("div.pagination-container li.current").data("paged");
2001        page = current - 1;
2002      }
2003      if (page == "next") {
2004        var current = $("div.pagination-container li.current").data("paged");
2005        page = current + 1;
2006      }
2007
2008      // preparing data for ajax
2009      var ajax_data = {
2010        action: "listeo_bookings_manage",
2011        date_start: startDataSql,
2012        date_end: endDataSql,
2013        listing_id: $("#listing_id").val(),
2014        listing_status: $("#listing_status").val(),
2015        booking_author: $("#booking_author").val(),
2016        dashboard_type: $("#dashboard_type").val(),
2017        limit: bookingsLimit,
2018        offset: bookingsOffset,
2019        page: page,
2020        //'nonce': nonce
2021      };
2022
2023      // display loader class
2024      $(".dashboard-list-box").addClass("loading");
2025
2026      $.ajax({
2027        type: "POST",
2028        dataType: "json",
2029        url: listeo.ajaxurl,
2030        data: ajax_data,
2031
2032        success: function (data) {
2033          // display loader class
2034          $(".dashboard-list-box").removeClass("loading");
2035
2036          if (data.data.html) {
2037            $("#no-bookings-information").hide();
2038            $("ul#booking-requests").html(data.data.html);
2039            $(".pagination-container").html(data.data.pagination);
2040          } else {
2041            $("ul#booking-requests").empty();
2042            $(".pagination-container").empty();
2043            $("#no-bookings-information").show();
2044          }
2045        },
2046      });
2047    }
2048
2049    $("#dashboard-booking-author-search").autocomplete({
2050      source: function (req, response) {
2051        $.getJSON(
2052          listeo_core.ajax_url +
2053            "?callback=?&action=listeo_core_incremental_listing_suggest",
2054          req,
2055          response
2056        );
2057      },
2058      select: function (event, ui) {
2059        window.location.href = ui.item.link;
2060      },
2061      minLength: 3,
2062    });
2063
2064    // hooks for get bookings into view
2065    $("#booking-date-range").on("apply.daterangepicker", function (e) {
2066      listeo_bookings_manage();
2067    });
2068    $("#listing_id").on("change", function (e) {
2069      listeo_bookings_manage();
2070    });
2071    $("#listing_status").on("change", function (e) {
2072      listeo_bookings_manage();
2073    });
2074    $("#booking_author").on("change", function (e) {
2075      listeo_bookings_manage();
2076    });
2077
2078    $("div.pagination-container").on("click", "a", function (e) {
2079      e.preventDefault();
2080
2081      var page = $(this).parent().data("paged");
2082
2083      listeo_bookings_manage(page);
2084
2085      $("body, html").animate(
2086        {
2087          scrollTop: $(".dashboard-list-box").offset().top,
2088        },
2089        600
2090      );
2091
2092      return false;
2093    });
2094
2095    $(document).on("click", ".reject, .cancel", function (e) {
2096      e.preventDefault();
2097      if (window.confirm(listeo_core.areyousure)) {
2098        var $this = $(this);
2099        $this.parents("li").addClass("loading");
2100        var status = "confirmed";
2101        if ($(this).hasClass("reject")) status = "cancelled";
2102        if ($(this).hasClass("cancel")) status = "cancelled";
2103
2104        // preparing data for ajax
2105        var ajax_data = {
2106          action: "listeo_bookings_manage",
2107          booking_id: $(this).data("booking_id"),
2108          status: status,
2109          //'nonce': nonce
2110        };
2111        $.ajax({
2112          type: "POST",
2113          dataType: "json",
2114          url: listeo.ajaxurl,
2115          data: ajax_data,
2116
2117          success: function (data) {
2118            // display loader class
2119            $this.parents("li").removeClass("loading");
2120
2121            listeo_bookings_manage();
2122          },
2123        });
2124      }
2125    });
2126
2127    $(document).on("click", ".delete", function (e) {
2128      e.preventDefault();
2129      if (window.confirm(listeo_core.areyousure)) {
2130        var $this = $(this);
2131        $this.parents("li").addClass("loading");
2132        var status = "deleted";
2133
2134        // preparing data for ajax
2135        var ajax_data = {
2136          action: "listeo_bookings_manage",
2137          booking_id: $(this).data("booking_id"),
2138          status: status,
2139          //'nonce': nonce
2140        };
2141        $.ajax({
2142          type: "POST",
2143          dataType: "json",
2144          url: listeo.ajaxurl,
2145          data: ajax_data,
2146
2147          success: function (data) {
2148            // display loader class
2149            $this.parents("li").removeClass("loading");
2150
2151            listeo_bookings_manage();
2152          },
2153        });
2154      }
2155    });
2156
2157    $(document).on("click", ".renew_booking", function (e) {
2158      e.preventDefault();
2159      if (window.confirm(listeo_core.areyousure)) {
2160        var $this = $(this);
2161        $this.parents("li").addClass("loading");
2162
2163        // preparing data for ajax
2164        var ajax_data = {
2165          action: "listeo_bookings_renew_booking",
2166          booking_id: $(this).data("booking_id"),
2167          //'nonce': nonce
2168        };
2169        $.ajax({
2170          type: "POST",
2171          dataType: "json",
2172          url: listeo.ajaxurl,
2173          data: ajax_data,
2174
2175          success: function (data) {
2176            if (data.success) {
2177            } else {
2178              alert(listeo_core.booked_dates);
2179            }
2180            // display loader class
2181            $this.parents("li").removeClass("loading");
2182
2183            listeo_bookings_manage();
2184          },
2185        });
2186      }
2187    });
2188
2189    $(document).on("click", ".approve", function (e) {
2190      e.preventDefault();
2191      var $this = $(this);
2192      $this.parents("li").addClass("loading");
2193      var status = "confirmed";
2194      if ($(this).hasClass("reject")) status = "cancelled";
2195      if ($(this).hasClass("cancel")) status = "cancelled";
2196
2197      // preparing data for ajax
2198      var ajax_data = {
2199        action: "listeo_bookings_manage",
2200        booking_id: $(this).data("booking_id"),
2201        status: status,
2202        //'nonce': nonce
2203      };
2204      $.ajax({
2205        type: "POST",
2206        dataType: "json",
2207        url: listeo.ajaxurl,
2208        data: ajax_data,
2209
2210        success: function (data) {
2211          // display loader class
2212          $this.parents("li").removeClass("loading");
2213
2214          listeo_bookings_manage();
2215        },
2216      });
2217    });
2218    $(document).on("click", ".mark-as-paid", function (e) {
2219      e.preventDefault();
2220      var $this = $(this);
2221      $this.parents("li").addClass("loading");
2222      var status = "paid";
2223
2224      // preparing data for ajax
2225      var ajax_data = {
2226        action: "listeo_bookings_manage",
2227        booking_id: $(this).data("booking_id"),
2228        status: status,
2229               //'nonce': nonce
2230      };
2231      $.ajax({
2232        type: "POST",
2233        dataType: "json",
2234        url: listeo.ajaxurl,
2235        data: ajax_data,
2236
2237        success: function (data) {
2238          // display loader class
2239          $this.parents("li").removeClass("loading");
2240
2241          listeo_bookings_manage();
2242        },
2243      });
2244    });
2245
2246    var start = moment().subtract(30, "days");
2247    var end = moment();
2248
2249    function cb(start, end) {
2250      $("#booking-date-range span,#chart-date-range span").html(
2251        start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY")
2252      );
2253    }
2254
2255    var ranges = new Object();
2256    ranges[listeo_core.today] = [moment().subtract(1, "days"), moment()];
2257    ranges[listeo_core.yesterday] = [
2258      moment().subtract(1, "days"),
2259      moment().subtract(1, "days"),
2260    ];
2261    ranges[listeo_core.last_7_days] = [moment().subtract(6, "days"), moment()];
2262    ranges[listeo_core.last_30_days] = [
2263      moment().subtract(29, "days"),
2264      moment(),
2265    ];
2266    ranges[listeo_core.this_month] = [
2267      moment().startOf("month"),
2268      moment().endOf("month"),
2269    ];
2270    ranges[listeo_core.last_month] = [
2271      moment().subtract(1, "month").startOf("month"),
2272      moment().subtract(1, "month").endOf("month"),
2273    ];
2274
2275    var today = listeo_core.today;
2276
2277    $("#booking-date-range-enabler").on("click", function (e) {
2278      e.preventDefault();
2279      $(this).hide();
2280      cb(start, end);
2281      $("#booking-date-range,#chart-date-range")
2282        .show()
2283        .daterangepicker(
2284          {
2285            opens: "left",
2286            autoUpdateInput: false,
2287            alwaysShowCalendars: true,
2288            startDate: start,
2289            endDate: end,
2290            ranges: ranges,
2291            locale: {
2292              format: wordpress_date_format.date,
2293              firstDay: parseInt(wordpress_date_format.day),
2294              applyLabel: listeo_core.applyLabel,
2295              cancelLabel: listeo_core.cancelLabel,
2296              fromLabel: listeo_core.fromLabel,
2297              toLabel: listeo_core.toLabel,
2298              customRangeLabel: listeo_core.customRangeLabel,
2299              daysOfWeek: [
2300                listeo_core.day_short_su,
2301                listeo_core.day_short_mo,
2302                listeo_core.day_short_tu,
2303                listeo_core.day_short_we,
2304                listeo_core.day_short_th,
2305                listeo_core.day_short_fr,
2306                listeo_core.day_short_sa,
2307              ],
2308              monthNames: [
2309                listeo_core.january,
2310                listeo_core.february,
2311                listeo_core.march,
2312                listeo_core.april,
2313                listeo_core.may,
2314                listeo_core.june,
2315                listeo_core.july,
2316                listeo_core.august,
2317                listeo_core.september,
2318                listeo_core.october,
2319                listeo_core.november,
2320                listeo_core.december,
2321              ],
2322            },
2323          },
2324          cb
2325        )
2326        .trigger("click");
2327      cb(start, end);
2328    });
2329
2330    // Calendar animation and visual settings
2331    $("#booking-date-range").on("show.daterangepicker", function (ev, picker) {
2332      $(".daterangepicker").addClass(
2333        "calendar-visible calendar-animated bordered-style"
2334      );
2335      $(".daterangepicker").removeClass("calendar-hidden");
2336    });
2337    $("#booking-date-range").on("hide.daterangepicker", function (ev, picker) {
2338      $(".daterangepicker").removeClass("calendar-visible");
2339      $(".daterangepicker").addClass("calendar-hidden");
2340    });
2341  } // end if dashboard booking
2342
2343  // $('a.reject').on('click', function() {
2344
2345  // 	console.log(picker);
2346
2347  // });
2348});
2349
2350})(this.jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.