
(function ($) {
  "use strict";
  /*=================================
    JS Index Here
  ==================================*/
  /*
 01. Mobile Menu
 02. MySwiper Logo
 03. Hero Swiper Slider
 04. Subscribe To instagram Slider
 05. Swiper Top
 06. Trending Stories Swiper
 07. Trending Posts Swiper
 08. Trending Posts Swiper
 09. Select Country
 10. Aos
 11. Dark Mode
 12. Header Search
 
*/
  /*=================================
       JS Index End
   ==================================*/

  /*=================================
       Mobile Menu
   ==================================*/
  $("#primary-menu").slicknav({
    allowParentLinks: true,
    prependTo: '#mobile',
    label: 'Menu',
  });

  var sf = $('#primary-menu').superfish({
    delay: 500, // one second delay on mouseout
    animation: { opacity: 'show', height: 'show' }, // fade-in and slide-down animation
    speed: 'fast', // faster animation speed
  });

  /*============================
      Header Search
    ============================*/
  if ($(".search-open").length) {
    $(".search-open").on("click", function (e) {
      e.preventDefault();
      $(".header-search-popup").toggleClass("active");
    });
  }

    // Theme Preloader
    $(window).on("load", function() {
      if ($(".preloader-area").length) {
          $(".preloader-area").fadeOut();
      }
  });
  // Sticky Menu Premium
  $(window).on('scroll', function () {
    var scroll = $(window).scrollTop();
    if (scroll < 100) {
      $("#sticky-header").removeClass("sticky-bar");
    } else {
      $("#sticky-header").addClass("sticky-bar");
    }
  });

  /*============================
      MySwiper Logo
    ============================*/
  $(document).ready(function () {
    let swiper = new Swiper(".update-post-swiper-slider", {
      spaceBetween: 22,
      centeredSlides: true,
      loop: true,
      speed: 3000,
      allowTouchMove: true,
      breakpoints: {
        0: {
          slidesPerView: 1,
        },
        520: {
          slidesPerView: 2,
        },
        620: {
          slidesPerView: 3,
        },
        950: {
          slidesPerView: 5,
        },
        1200: {
          slidesPerView: 6,
        },
        1400: {
          slidesPerView: 6,
        },
        1700: {
          slidesPerView: 9,
        },

      },
    });
  });

  /*=================================
       Hero Swiper Slider
   ==================================*/
  $(document).ready(function () {
    let swiper = new Swiper(".hero-swiper-slider", {
      slidesPerView: 1,
      spaceBetween: 10,
      centeredSlides: true,
      grabCursor: true,
      loop: true,
      speed: 3000,
      autoplay: {
        delay: 3000,
        disableOnInteraction: false,
      },
      parallax: true,
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });
  });


  /*=================================
       Subscribe To instagram Slider
   ==================================*/
  $(document).ready(function () {
    let swiper = new Swiper(".subscribe-to-instagram-slider", {
      spaceBetween: 22,
      centeredSlides: true,
      speed: 3000,
      grabCursor: true,
      autoplay: {
        disableOnInteraction: true,
        delay: 0,
      },
      loop: true,
      breakpoints: {
        0: {
          slidesPerView: 1,
        },
        520: {
          slidesPerView: 1,
        },
        620: {
          slidesPerView: 2,
        },
        950: {
          slidesPerView: 3,
        },
        1200: {
          slidesPerView: 3,
        },
        1400: {
          slidesPerView: 3,
        },
        1700: {
          slidesPerView: 5,
        },

      },
    });
  });


  /*=================================
       Trending Stories Swiper
   ==================================*/
  $(document).ready(function () {
    var swiper = new Swiper('.trending-stories-swiper', {
      slidesPerView: 4,
      grabCursor: true,
      autoplay: {
        delay: 2500,
      },
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
        renderBullet: function (index, className) {
          return `<span class="${className}">${index + 1}</span>`;
        },
      },
      breakpoints: {
        0: {
          slidesPerView: 1,
          spaceBetween: 30,
        },
        520: {
          slidesPerView: 2,
        },
        950: {
          slidesPerView: 2,
        },
        1200: {
          slidesPerView: 3,
          spaceBetween: 20,
        },
        1400: {
          slidesPerView: 3,
        },
        1600: {
          slidesPerView: 4,
          spaceBetween: 190,
        },
      },
    });
  });



  /*=================================
       Trending Posts Swiper
   ==================================*/
  $(document).ready(function () {
    var swiper = new Swiper(".trending-posts-swiper", {
      spaceBetween: 10,
      slidesPerView: 100,
      freeMode: true,
      watchSlidesProgress: true,
      speed: 3000,
      autoplay: {
        delay: 2500,
        disableOnInteraction: false,
      },
    });

    var swiper2 = new Swiper(".trending-posts-swiper2", {
      spaceBetween: 10,
      speed: 3000,
      autoplay: {
        delay: 2500,
        disableOnInteraction: false,
      },
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
      thumbs: {
        swiper: swiper,
      },
    });
  });



  /*============================
       Bottom To Top
     =============================*/
  const toTop = document.querySelector(".to-top");
  window.addEventListener("scroll", () => {
    if (window.pageYOffset > 100) {
      toTop.classList.add("active");
    }
    else {
      toTop.classList.remove("active");
    }
  })
  /*============================
      Video play Magnific Popup
     ============================*/
  $(document).ready(function () {
    $('.video-button').magnificPopup({
      disableOn: 700,
      type: 'iframe',
      mainClass: 'mfp-fade',
      removalDelay: 160,
      preloader: false,

      fixedContentPos: false
    });
  });
  /*============================
       Gallery Slider
      ============================*/
  var swiper = new Swiper(".gallery-slider", {
    loop: true,
    autoplay: {
      delay: 2500,
      disableOnInteraction: false,
    },
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
  });
  /*============================
      Aos Animation
    ============================*/
  $(document).ready(function () {
    AOS.init();
  });

  // WooCommerce product Popup
  var $rtl = $('body').hasClass("rtl") ? true : false;
  
  // Grid View and List View
  if ($('#newscope-shop-view-mode li').length) {
      $('#newscope-shop-view-mode li').on('click', function() {
          $('body').removeClass('newscope-product-grid-view').removeClass('newscope-product-list-view');

          if ($(this).hasClass('newscope-shop-list')) {
              $('body').addClass('newscope-product-list-view');
              Cookies.set('newscope-shop-view', 'list');
          } else {
              $('body').addClass('newscope-product-grid-view');
              Cookies.remove('newscope-shop-view');
          }
          return false;
      });
  }


  document.addEventListener('DOMContentLoaded', () => {
    const darkSwitch = document.querySelector('#darkswitch');
    const htmlElement = document.documentElement;
    const hiddenThemeModeInput = document.querySelector('#hiddenThemeMode');
    const defaultTheme = 'light'; // Set a default theme if no other sources are available
    function setThemeMode(mode) {
      htmlElement.setAttribute('data-theme-mode', mode);
      localStorage.setItem('themeMode', mode); // Save the mode to localStorage
    }
    function loadThemeMode() {
      // Check the hidden input value first
      const hiddenThemeMode = hiddenThemeModeInput ? hiddenThemeModeInput.value : null;
      if (hiddenThemeMode) {
        setThemeMode(hiddenThemeMode);
        if (darkSwitch) {
          darkSwitch.checked = hiddenThemeMode === 'dark';
        }
      } else {
        // Fallback to localStorage
        const storedTheme = localStorage.getItem('themeMode');
        if (storedTheme) {
          setThemeMode(storedTheme);
          if (darkSwitch) {
            darkSwitch.checked = storedTheme === 'dark';
          }
        } else {
          // Fallback to the default theme
          setThemeMode(defaultTheme);
          if (darkSwitch) {
            darkSwitch.checked = defaultTheme === 'dark';
          }
        }
      }
    }
    if (darkSwitch) {
      darkSwitch.addEventListener('change', function () {
        const newMode = darkSwitch.checked ? 'dark' : 'light';
        setThemeMode(newMode); // This should save the mode to localStorage
      });
    }
    // Load the theme mode when the page loads
    loadThemeMode();
  });
  


  $(document).ready(function() {
    var swiper = new Swiper(".woo-product-shop-swiper", {
      spaceBetween: 10,
      slidesPerView: 6,
      freeMode: true,
      watchSlidesProgress: true,
    });
  
    var swiper2 = new Swiper(".woo-product-shop-swiper2", {
      spaceBetween: 10,
      centeredSlides: true,
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
      thumbs: {
        swiper: swiper,
      },
    });
  });
  



  $(document).ready(function(){
    // Initialize Magnific Popup on elements with class 'image-popup-vertical-fit'
    $('.image-popup-vertical-fit').magnificPopup({
        type: 'image', // Type of content to display (image)
        mainClass: 'mfp-with-zoom', // Class to be added to the popup for custom styling

        // Enable gallery mode
        gallery: {
            enabled: true // Allow navigating through a gallery of images
        },

        // Enable zoom effect
        zoom: {
            enabled: true, // Enable zoom effect
            duration: 300, // Duration of the zoom effect in milliseconds
            easing: 'ease-in-out', // Easing function for the zoom effect

            // Define the element that will trigger the zoom effect
            opener: function(openerElement) {
                // If the openerElement is an image, return it; otherwise, find an image within it
                return openerElement.is('img') ? openerElement : openerElement.find('img');
            }
        }
    });
});


})(jQuery);  