/** Shopify CDN: Minification failed

Line 16:0 Unexpected "<"
Line 19:4 Comments in CSS use "/* ... */" instead of "//"
Line 26:4 Comments in CSS use "/* ... */" instead of "//"
Line 26:50 Unterminated string token
Line 38:4 Comments in CSS use "/* ... */" instead of "//"
Line 38:72 Unterminated string token
Line 56:4 Comments in CSS use "/* ... */" instead of "//"
Line 71:4 Comments in CSS use "/* ... */" instead of "//"
Line 78:4 Comments in CSS use "/* ... */" instead of "//"
Line 93:4 Comments in CSS use "/* ... */" instead of "//"
... and 1 more hidden warnings

**/
<script>
document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('slideshow-component').forEach(function (el) {
    // Enable fade mode on this slideshow
    el.classList.add('fade-slideshow');

    const track = el.querySelector('.slideshow.banner');
    const slides = Array.from(el.querySelectorAll('.slideshow__slide'));
    if (!track || slides.length < 2) return;

    // Keep height so the section doesn't collapse
    function setHeight() {
      const h = track.getBoundingClientRect().height || slides[0].getBoundingClientRect().height;
      if (h) track.style.minHeight = h + 'px';
    }
    setHeight();
    window.addEventListener('resize', setHeight);
    slides.forEach(s => s.querySelectorAll('img,video').forEach(m => {
      m.addEventListener('load', setHeight, { passive: true });
      if (m.readyState >= 2 || m.complete) setHeight();
    }));

    // Initial active index (fallback to 0 if aria-hidden isn't set yet)
    let i = Math.max(0, slides.findIndex(s => s.getAttribute('aria-hidden') === 'false'));
    if (i < 0) i = 0;

    function show(idx) {
      slides.forEach((s, n) => {
        if (n === idx) {
          s.classList.add('is-active');
          s.setAttribute('aria-hidden', 'false');
        } else {
          s.classList.remove('is-active');
          s.setAttribute('aria-hidden', 'true');
        }
      });
      i = idx;
    }
    show(i);

    // Hook prev/next buttons
    const prev = el.querySelector('button[name="previous"]');
    const next = el.querySelector('button[name="next"]');
    function interceptClick(btn, delta) {
      if (!btn) return;
      btn.addEventListener('click', function (e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        const nextIndex = (i + delta + slides.length) % slides.length;
        show(nextIndex);
      });
    }
    interceptClick(prev, -1);
    interceptClick(next, +1);

    // Stop the native horizontal scroll from fighting us
    const container = el.querySelector('.slider') || track;
    if (container) {
      container.style.scrollBehavior = 'auto';
      container.addEventListener('scroll', function () { container.scrollLeft = 0; }, { passive: true });
    }

    // Optional: autoplay support (reads Dawn data attributes if present)
    const interval = parseInt(el.dataset.interval || '5000', 10);
    const shouldAutoplay = (el.dataset.autoplay || '').toString() === 'true';
    let timer = null;
    function start() { stop(); timer = setInterval(() => show((i + 1) % slides.length), interval); }
    function stop() { if (timer) clearInterval(timer), timer = null; }
    if (shouldAutoplay) start();

    const autoBtn = el.querySelector('.slideshow__autoplay');
    if (autoBtn) {
      autoBtn.addEventListener('click', function () {
        if (timer) stop(); else start();
      });
    }

    // Re-apply after Theme Editor changes
    document.addEventListener('shopify:section:load', setHeight);
  });
});
</script>
