/** ============================================================
 *  JS File for Kipya Template
 *===============================================================*/

/**const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]')
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl))
const popover = new bootstrap.Popover('.menu-popover', {
    container: '.modal-body'
  })**/

  $(document).ready(function () {
    // Toggle popover on button click
    $("#menuButton").click(function () {
        $(".popoverz").fadeToggle();
    });

    // Close popover when clicking outside
    $(document).click(function (event) {
        if (!$(event.target).closest('#menuButton, .popoverz').length) {
            $(".popoverz").fadeOut();
        }
    });
    
    //Social Icons on Mobile
     $(window).scroll(function() {
            // Get the current scroll position
            var scrollPosition = $(this).scrollTop();

            // Check if the scroll position is greater than or equal to 200px
            if (scrollPosition >= 200) {
                // If yes, add the class 'socialmedia-off' to hide the social icons
                $('.social-home').addClass('socialmedia-off');
            } else {
                // If not, remove the class 'socialmedia-off' to show the social icons
                $('.social-home').removeClass('socialmedia-off');
            }
        });
});


/**====================================================
   * Slides - Animation JS
   *====================================================**/
function thmSwiperInit() {
    // swiper slider
    if ($(".thm-swiper__slider").length) {
      $(".thm-swiper__slider").each(function () {
        let elm = $(this);
        let options = elm.data('swiper-options');
        let thmSwiperSlider = new Swiper(elm, options);
      });
    }
  }
  if ($(".banner-bg-slide").length) {
    $(".banner-bg-slide").each(function () {
      var Self = $(this);
      var bgSlideOptions = Self.data("options");
      var bannerTwoSlides = Self.vegas(bgSlideOptions);
    });
  }
  if ($(".wow").length) {
    var wow = new WOW({
      boxClass: "wow", // animated element css class (default is wow)
      animateClass: "animated", // animation css class (default is animated)
      mobile: true, // trigger animations on mobile devices (default is true)
      live: true // act on asynchronously loaded content (default is true)
    });
    wow.init();
  }
    // window load event
    $(window).on("load", function () {

      thmSwiperInit();
      thmOwlInit();
      handlePreloader();
      languageSwitcher();
      projectMasonaryLayout();
  
  
      //Jquery Spinner / Quantity Spinner
      if ($('.quantity-spinner').length) {
        $("input.quantity-spinner").TouchSpin({
          verticalbuttons: true
        });
      }
  
    });

    /**====================================
     * AOS
     =====================================**/
     document.addEventListener('DOMContentLoaded', function () {
    // Initialize AOS for each column
    if (typeof AOS !== 'undefined') {
        AOS.init({
            duration: 1000,
            easing: 'ease-in-out',
            once: true,
            mirror: false,
        });
    }
});


/** ===============================================
 * Partner logos
 *=================================================*/

$(document).ready(function() {
  // Pause on mouseover
  $('.partner').hover(function() {
      $(this).find('.card').css('animation-play-state', 'paused');
  }, function() {
      $(this).find('.card').css('animation-play-state', 'running');
  });
});

/** ===============================================
 * Back to Top
 *=================================================*/
function select(selector) {
  return document.querySelector(selector);
}

// Check if the back-to-top element exists
var backtotop = select('.back-to-top');
if (backtotop) {
  const toggleBacktotop = () => {
      if (window.scrollY > 100) {
          backtotop.classList.add('active');
      } else {
          backtotop.classList.remove('active');
      }
  };
  window.addEventListener('load', toggleBacktotop);
  window.addEventListener('scroll', toggleBacktotop); // Change 'onscroll' to 'scroll'
}

