import GLightbox from "glightbox";

jQuery(function ($) {
  $(document).on("wpbs_form_updated", function () {
    $("#wpbs-edit-order").prop("href", "#reservation");
  });

  $(document).ready(function () {
    $(".wpbs-calendars-wrapper").before("<h3 id='reservation'>Rezervácia</h3>");
    $(".facilities").appendTo(".booking .wpbs-main-wrapper");
    $(".booking .wpbs-form-container").addClass("sticky-side-menu");
    $(".booking .wpbs-payment-confirmation").addClass("sticky-side-menu");

    var lightboxDescription = GLightbox({
      selector: ".single-accommodation .single-header .gallery-img",
    });
  });

  $(document).ready(function () {
    var elementGallery = $(".single-header-gal-col").find("a:visible:last"),
      count = $(".single-header-gal-col").children(":hidden").length,
      newdDiv = $("<div id='number-of-imgs'></div>");

    elementGallery.addClass("overlay");
    elementGallery.append(newdDiv);
    $("#number-of-imgs").append("+", count);
  });

  var $reservation_mobile_trigger = $("#reservation-trigger");
  var $reservation_mobile_close = $(".booking-mobile .close-btn");
  var $reservation_mobile = $(".booking-mobile");
  var $body = $("body");

  function show_mobile_reservation() {
    $reservation_mobile_trigger.toggleClass("active");
    $reservation_mobile.toggleClass("booking-mobile-active");
    $body.toggleClass("booking-mobile-active");
  }

  function hide_mobile_reservation() {
    $reservation_mobile_trigger.toggleClass("active");
    $reservation_mobile.removeClass("booking-mobile-active");
    $body.removeClass("booking-mobile-active");
  }

  $reservation_mobile_trigger.on("click", show_mobile_reservation);
  $reservation_mobile_close.on("click", hide_mobile_reservation);
});
