/* Scoped to: marathon-testimonials */
(function() {
  'use strict';
  var componentRoots = document.querySelectorAll('[data-component-slug="marathon-testimonials"]');
  componentRoots.forEach(function(componentRoot) {
    // Helper to query within component, with fallback to document for sibling elements
    var $ = function(sel) { 
      return componentRoot.querySelector(sel) || document.querySelector('[data-component-slug="marathon-testimonials"] ~ ' + sel) || document.querySelector(sel);
    };
    var $$ = function(sel) { 
      var results = componentRoot.querySelectorAll(sel);
      return results.length ? results : document.querySelectorAll(sel);
    };
    // Original component JS runs in this scope
    (function () { setTimeout(function () { var carousel = document.querySelector("[data-testimonials-carousel]"); if (!carousel) return; var slidesContainer = carousel.querySelector("[data-testimonials-slides]"); var dots = carousel.querySelectorAll("[data-dot]"); if (!slidesContainer || !dots.length) return; var currentIndex = 0; var autoScrollInterval = null; var autoScrollDelay = 4000; function updateDots(index) { dots.forEach(function (dot, i) { if (i === index) { dot.classList.remove("bg-gray-300"); dot.classList.add("bg-[#131416]"); } else { dot.classList.remove("bg-[#131416]"); dot.classList.add("bg-gray-300"); } }); } function scrollToIndex(index) { var cards = slidesContainer.children; if (cards.length === 0) return; var card = cards[index]; if (card) { slidesContainer.scrollTo({ left: card.offsetLeft - slidesContainer.offsetLeft, behavior: "smooth", }); currentIndex = index; updateDots(index); } } function nextSlide() { var cards = slidesContainer.children; var nextIndex = (currentIndex + 1) % cards.length; scrollToIndex(nextIndex); } function startAutoScroll() { if (autoScrollInterval) clearInterval(autoScrollInterval); autoScrollInterval = setInterval(nextSlide, autoScrollDelay); } function stopAutoScroll() { if (autoScrollInterval) { clearInterval(autoScrollInterval); autoScrollInterval = null; } } dots.forEach(function (dot, index) { dot.addEventListener("click", function () { scrollToIndex(index); stopAutoScroll(); startAutoScroll(); }); }); slidesContainer.addEventListener("mouseenter", stopAutoScroll); slidesContainer.addEventListener("mouseleave", startAutoScroll); slidesContainer.addEventListener("scroll", function () { var cards = slidesContainer.children; var scrollLeft = slidesContainer.scrollLeft; var containerWidth = slidesContainer.offsetWidth; var closestIndex = 0; var closestDistance = Infinity; for (var i = 0; i < cards.length; i++) { var cardCenter = cards[i].offsetLeft - slidesContainer.offsetLeft + cards[i].offsetWidth / 2; var distance = Math.abs(cardCenter - (scrollLeft + containerWidth / 2)); if (distance < closestDistance) { closestDistance = distance; closestIndex = i; } } if (closestIndex !== currentIndex) { currentIndex = closestIndex; updateDots(currentIndex); } }); updateDots(0); startAutoScroll(); }, 0); })();
  });
})();