/** Shopify CDN: Minification failed

Line 7:3 Unexpected "("
Line 8:16 Expected ":"

**/
if (!customElements.get('sst-feature-gallery')) {
  customElements.define(
    'sst-feature-gallery',
    class FeatureImageGallery extends HTMLElement {
      constructor() {
        super();

        this.stage = this.querySelector('[data-feature-gallery-stage]');
        this.templates = Array.from(this.querySelectorAll('[data-feature-gallery-template]'));
        this.initialSlide = this.stage?.firstElementChild?.cloneNode(true);
        this.slideCount = this.templates.length + 1;
        this.currentIndex = 0;
        this.pointerStartX = null;
        this.didSwipe = false;

        if (!this.stage || !this.initialSlide || this.slideCount < 2) return;

        this.addEventListener('click', (event) => {
          const previous = event.target.closest('[data-feature-gallery-previous]');
          const next = event.target.closest('[data-feature-gallery-next]');
          const dot = event.target.closest('[data-feature-gallery-dot]');

          if (previous) this.show(this.currentIndex - 1);
          if (next) this.show(this.currentIndex + 1);
          if (dot) this.show(Number(dot.dataset.featureGalleryDot));
        });

        this.addEventListener('keydown', (event) => {
          if (event.key === 'ArrowLeft') this.show(this.currentIndex - 1);
          if (event.key === 'ArrowRight') this.show(this.currentIndex + 1);
        });

        this.stage.addEventListener('pointerdown', (event) => {
          if (event.pointerType !== 'mouse') this.pointerStartX = event.clientX;
        });

        this.stage.addEventListener('pointerup', (event) => {
          if (this.pointerStartX === null) return;

          const distance = event.clientX - this.pointerStartX;
          this.pointerStartX = null;
          if (Math.abs(distance) < 45) return;

          this.didSwipe = true;
          this.show(this.currentIndex + (distance < 0 ? 1 : -1));
          window.setTimeout(() => { this.didSwipe = false; }, 0);
        });

        this.stage.addEventListener('click', (event) => {
          if (!this.didSwipe) return;
          event.preventDefault();
        }, true);
      }

      show(index) {
        const normalizedIndex = (index + this.slideCount) % this.slideCount;
        const nextSlide = normalizedIndex === 0
          ? this.initialSlide.cloneNode(true)
          : this.templates[normalizedIndex - 1]?.content.firstElementChild?.cloneNode(true);

        if (!nextSlide) return;

        this.stage.replaceChildren(nextSlide);
        this.currentIndex = normalizedIndex;
        this.querySelectorAll('[data-feature-gallery-dot]').forEach((dot, dotIndex) => {
          if (dotIndex === normalizedIndex) dot.setAttribute('aria-current', 'true');
          else dot.removeAttribute('aria-current');
        });
      }
    }
  );
}
