// Slider Section
jQuery(document).ready(function($) {
  const home_accessories_shop_section = $('.slider-section');
  const home_accessories_shop_owl = home_accessories_shop_section.find('.owl-carousel').owlCarousel({
    loop: true,
    margin: 15,
    nav: false,
    dots: false,
    rtl: false,
    items: 1,
    autoplay: true,
  });

  // Custom navigation
  home_accessories_shop_section.find('.custom-next').click(() => 
    home_accessories_shop_owl.trigger('next.owl.carousel')
  );
  home_accessories_shop_section.find('.custom-prev').click(() => 
    home_accessories_shop_owl.trigger('prev.owl.carousel')
  );

  // Custom dots (thumbnails)
  const home_accessories_shop_dots = home_accessories_shop_section.find('.custom-dots').empty();
  home_accessories_shop_section.find('.owl-item:not(.cloned)').each(function(i) {
    const img = $(this).find('img').attr('src');
    if (img) home_accessories_shop_dots.append(
      `<button class="dot" data-index="${i}"><img src="${img}" alt="thumb-${i}"></button>`
    );
  });

  home_accessories_shop_dots.on('click', '.dot', function() {
    home_accessories_shop_owl.trigger('to.owl.carousel', [$(this).data('index'), 300]);
  });

  // Slide count
  const home_accessories_shop_count = home_accessories_shop_section.find('.slide-count');
  const home_accessories_shop_total = home_accessories_shop_section.find('.owl-item:not(.cloned)').length;
  const home_accessories_shop_pad = n => (n < 10 ? '0' + n : n);
  home_accessories_shop_count.html(`<span class="current-slide">01</span> / <span class="total-slide">${home_accessories_shop_pad(home_accessories_shop_total)}</span>`);

  // Update on change
  home_accessories_shop_owl.on('changed.owl.carousel', function(e) {
    const index = (e.item.index - e.relatedTarget._clones.length / 2 + e.item.count) % e.item.count;
    home_accessories_shop_dots.find('.dot').removeClass('active').eq(index).addClass('active');
    home_accessories_shop_count.find('.current-slide').text(home_accessories_shop_pad(index + 1));
  });

  // Set first active
  home_accessories_shop_dots.find('.dot').eq(0).addClass('active');
});

// 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 home_accessories_shop_button = document.querySelector('.scroll-top-box');
  if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
    home_accessories_shop_button.style.display = "block";
  } else {
    home_accessories_shop_button.style.display = "none";
  }
};

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