//lazy load
(($) => {
  $(document).ready(() => {
    $("img.lazy-blanka").unveil();
    $(".match").matchHeight();
    // $('.tinvwl_add_to_wishlist-text').click(() => {
    //   $('.tinv-modal').animate('top', $('#main-header').outerHeight())
    // })
  });

  var localPickup = $("input.local_pickup");

  // SMOOTH SCROLL on all anchors
  $("a.smooth-scroll").click(function scrollAnchor(e) {
    e.preventDefault();
    const { location } = window;
    if (
      location.pathname.replace(/^\//, "") ===
        this.pathname.replace(/^\//, "") &&
      location.hostname === this.hostname
    ) {
      let target = $(this.hash);
      target = (target.length && target) || $(`[name=${this.hash.slice(1)}]`);
      if (target.length) {
        const targetOffset = target.offset().top;
        $("html,body").animate({ scrollTop: targetOffset }, 1000);
      }
    }
  });

  // Single product forms
  $(document).ready(function () {
    const popup = $(".offer-popup");

    $(".btn-product-offer, .cta-worn-product").on("click", function () {
        const formWrapperId = $(this).data("type");
        
        // Show the corresponding form based on formWrapperId
        showForm(formWrapperId);
    });

    $(".close-overlay").on("click", function () {
        $("body").removeClass("popup");
        $(".shadow").fadeOut();
        popup.fadeOut();
    });

    function showForm(formWrapperId) {
        // Hide all forms initially
        $(".offer-popup .inner-wrapper > div").hide();

        // Show the form based on formWrapperId
        $(`#${formWrapperId}`).show();

        // Show the popup
        $("body").addClass("popup");
        $(".shadow").fadeIn();
        popup.fadeIn();
    }
  });

})(jQuery);
