// Slider Section
jQuery(document).ready(function($) {
  const chocolate_house_section = $('.slider-sections');
  const chocolate_house_owl = chocolate_house_section.find('.owl-carousel').owlCarousel({
    loop: true,
    margin: 15,
    nav: false,
    dots: false,
    rtl: false,
    items: 1,
    // autoplay: true,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
  });

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

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

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

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

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

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

jQuery(document).ready(function () {
  var chocolate_house_swiper_testimonials = new Swiper(".testimonial-swiper-slider.mySwiper", {
    slidesPerView: 3,
      spaceBetween: 50,
      speed: 1000,
      autoplay: {
        delay: 3000,
        disableOnPoppinsaction: false,
      },
      navigation: {
        nextEl: ".testimonial-swiper-button-next",
        prevEl: ".testimonial-swiper-button-prev",
      },
      breakpoints: {
        0: {
          slidesPerView: 1,
        },
        767: {
          slidesPerView: 2,
        },
        1023: {
          slidesPerView: 3,
        }
    },
  });
});
