// Scroll to Top
window.onscroll = function() {
  const dropshipping_shop_button = document.querySelector('.scroll-top-box');
  if (dropshipping_shop_button) {
    if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
      dropshipping_shop_button.style.display = "block";
    } else {
      dropshipping_shop_button.style.display = "none";
    }
  }
};

const scrollTopLink = document.querySelector('.scroll-top-box a');
if (scrollTopLink) {
  scrollTopLink.onclick = function(event) {
    event.preventDefault();
    window.scrollTo({ top: 0, behavior: 'smooth' });
  };
}

/*------------------------------------------------
              Homepage slider
------------------------------------------------*/
document.addEventListener("DOMContentLoaded", function () {
  const swiperContainer = document.querySelector(".pest-control-company-swiper");
  if (swiperContainer) {
    var pest_control_company_Slider = new Swiper(swiperContainer, {
      slidesPerView: 1,
      speed: 1000,
      autoplay: false,
      navigation: {
        nextEl: ".pest-control-company-swiper-button-next",
        prevEl: ".pest-control-company-swiper-button-prev",
      },
      loop: true,
      on: {
        init: function () {
          pest_control_company_updateSlideNumbers(this);
        },
        slideChange: function () {
          pest_control_company_updateSlideNumbers(this);
        },
      },
    });

    function pest_control_company_updateSlideNumbers(swiper) {
      var realSlides = swiper.el.querySelectorAll('.swiper-slide:not(.swiper-slide-duplicate)');
      var total = realSlides.length;
      var current = swiper.realIndex + 1;
      var next = (current % total) + 1;

      var slideCurrent = document.querySelector('.slide-current');
      var slideNext = document.querySelector('.slide-next');

      if (slideCurrent) slideCurrent.textContent = ("0" + current).slice(-2);
      if (slideNext) slideNext.textContent = ("0" + next).slice(-2);
    }
  }
});

// our services
jQuery(document).ready(function() {
  jQuery('.service-sec .owl-carousel').owlCarousel({
    loop: true,
    margin: 20,
    nav: true,
    dots: false,
    rtl: false,
    responsive: {
    0: { 
      items: 1 
    },
    600: { 
      items: 2 
    },
    767: { 
      items: 3 
    },
    1200: { 
      items: 3 
    }
  },
    autoplay: true,
  });
});