// Main Slider
jQuery(document).ready(function() {
  jQuery('.slider-section .owl-carousel').owlCarousel({
    loop: true,
    margin: 30,
    nav: false, 
    dots: true,
    rtl: false,
    items: 1,
    autoplay: true,
  });
});

// Product Section
jQuery(document).ready(function() {
  jQuery('.product-section .owl-carousel').owlCarousel({
    loop: true,
    margin: 30,
    nav: true,
    navText: ["<span class='dashicons dashicons-arrow-left-alt'></span>", "<span class='dashicons dashicons-arrow-right-alt'></span>"], 
    dots: false,
    rtl: false,
    responsive: {
    0: { 
      items: 1 
    },
    600: { 
      items: 2 
    },
    992: { 
      items: 3 
    },
    1200: { 
      items: 4 
    }
  },
  autoplay: true,
  });
});

// Testimonial Section
jQuery(document).ready(function() {
  jQuery('.testimonial-section .owl-carousel').owlCarousel({
    loop: true,
    margin: 15,
    nav: true,
    navText: ["<span class='left-btn p-3'></span>", "<span class='right-btn p-3'></span>"], 
    dots: false,
    rtl: false,
    responsive: {
    0: { 
      items: 1 
    },
    768: { 
      items: 2 
    },
    992: { 
      items: 2 
    },
    1200: { 
      items: 3 
    }
  },
  autoplay: true,
  });
});

// News Section
jQuery(document).ready(function() {
  jQuery('.news-section .owl-carousel').owlCarousel({
    loop: true,
    margin: 15,
    nav: false, 
    dots: false,
    rtl: false,
    responsive: {
    0: { 
      items: 1 
    },
    768: { 
      items: 2 
    },
    992: { 
      items: 2 
    },
    1200: { 
      items: 3 
    }
  },
  autoplay: true,
  });
});

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

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

//  Single Product Link
document.addEventListener("click", function (e) {
  const vehicle_detailing_btn = e.target.closest(".product-btn");
  if (!vehicle_detailing_btn) return;

  const vehicle_detailing_product = vehicle_detailing_btn.closest(".product, .wc-block-product, li");
  if (!vehicle_detailing_product) return;

  const vehicle_detailing_link = vehicle_detailing_product.querySelector("a[href]");
  if (!vehicle_detailing_link) return;

  e.preventDefault();
  window.location.href = vehicle_detailing_link.href;
}, true);
