import { r as g, c as r, h as o, H as u, g as f } from "./index.e6beb8d9.js";
import { d as x, e as m } from "./bodyScrollLock.esm-B0kNlhKL.c7a66a82.js";
import { c as p } from "./index-orsBiyT_.fc4357c3.js";
import { t as h } from "./index.esm-DBTxpXCn.fccbd562.js";
import { q as v } from "./utils-CCck-DTo.e4e43b6a.js";
import "react";
import "react-dom";
const S = () => ":host{display:block}:host *{box-sizing:border-box}.lightbox{--swirl-lightbox-view-height:100vh;position:fixed;z-index:var(--s-z-40);display:block;overflow:visible;width:auto;max-width:none;height:var(--swirl-lightbox-view-height);max-height:none;margin:0;padding:0;border:none;background-color:rgba(0, 0, 0, 1);inset:0}.lightbox::backdrop{display:none}.lightbox:not([open]){display:none}@supports (height: 100dvh){.lightbox{--swirl-lightbox-view-height:100dvh}}@media (min-width: 768px){.lightbox{background-color:rgba(0, 0, 0, 0.8)}}.lightbox:not(.lightbox--closing) .lightbox__body{animation:0.15s lightbox-fade-in}@media (prefers-reduced-motion){.lightbox:not(.lightbox--closing) .lightbox__body{animation:none}}.lightbox--closing{animation:0.15s lightbox-fade-out;animation-fill-mode:forwards}@media (prefers-reduced-motion){.lightbox--closing{animation:none}}.lightbox__body{position:relative;width:100%;height:100%}.lightbox__header{position:absolute;z-index:1;top:0;right:0;left:0;display:flex;padding:var(--s-space-12) var(--s-space-16);align-items:flex-start;pointer-events:none;gap:var(--s-space-12);justify-content:space-between}.lightbox__header .lightbox__close-button{order:-1}@media (min-width: 768px){.lightbox__header{justify-content:flex-end}.lightbox__header .lightbox__close-button{order:unset}}.lightbox__toolbar{display:flex;align-items:center;pointer-events:auto;gap:var(--s-space-12)}.lightbox__controls{position:absolute;z-index:1;top:50%;right:0;left:0;display:none;padding-right:var(--s-space-16);padding-left:var(--s-space-16);justify-content:space-between;align-items:flex-start;pointer-events:none}@media (min-width: 768px){.lightbox__controls{display:flex}}.lightbox__close-button,.lightbox__download-button,.lightbox__previous-slide-button,.lightbox__next-slide-button{display:inline-flex;width:2.5rem;height:2.5rem;justify-content:center;align-items:center;border:none;border-radius:50%;color:var(--s-icon-on-image);background-color:rgba(0, 0, 0, 0.6);cursor:pointer;transition:opacity 0.15s;pointer-events:auto}.lightbox__close-button:disabled,.lightbox__download-button:disabled,.lightbox__previous-slide-button:disabled,.lightbox__next-slide-button:disabled{pointer-events:none;opacity:0}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.lightbox__close-button,.lightbox__download-button,.lightbox__previous-slide-button,.lightbox__next-slide-button{width:2.25rem;height:2.25rem}}.lightbox__content{overflow:hidden;width:100%;height:100%;-webkit-user-select:none;-moz-user-select:none;user-select:none}.lightbox__slides{display:flex;width:100%;height:100%}.lightbox__slides ::slotted(*){flex-basis:100%;flex-shrink:0;transition:transform 0.3s}@media (min-width: 768px){.lightbox__slides ::slotted(*){padding:4rem 5rem}}@media (prefers-reduced-motion){.lightbox__slides ::slotted(*){transition:none}}.lightbox__pagination{position:absolute;bottom:var(--s-space-32);left:50%;padding:var(--s-space-4) var(--s-space-12);border-radius:var(--s-border-radius-base);color:var(--s-text-on-image);background-color:rgba(0, 0, 0, 0.6);font-weight:var(--s-font-weight-medium);line-height:var(--s-line-height-base);transform:translateX(-50%);pointer-events:none}@media (min-width: 768px){.lightbox__pagination{display:none}}@keyframes lightbox-fade-in{from{opacity:0}to{opacity:1}}@keyframes lightbox-fade-out{from{opacity:1}to{opacity:0}}", _ = class {
  constructor(t) {
    g(this, t), this.activeSlideChange = r(this, "activeSlideChange", 7), this.lightboxClose = r(this, "lightboxClose", 7), this.closeButtonLabel = "Close modal", this.downloadButtonEnabled = !0, this.downloadButtonLabel = "Download", this.nextSlideButtonLabel = "Next slide", this.previousSlideButtonLabel = "Previous slide", this.activeSlideIndex = 0, this.closing = !1, this.opening = !1, this.componentLoaded = !1, this.dragging = !1, this.onKeyDown = (e) => {
      e.code === "Escape" ? (e.stopImmediatePropagation(), e.preventDefault(), this.close()) : e.code === "ArrowLeft" ? this.onPreviousSlideClick() : e.code === "ArrowRight" && this.onNextSlideClick();
    }, this.preventDragStart = (e) => {
      e.preventDefault();
    }, this.onCloseButtonClick = () => {
      this.close();
    }, this.onDownloadButtonClick = () => {
      var e;
      (e = this.slides[this.activeSlideIndex]) == null || e.download();
    }, this.onNextSlideClick = () => {
      var e;
      this.activateSlide(Math.min(this.slides.length - 1, this.activeSlideIndex + 1)), this.activeSlideIndex === this.slides.length - 1 && (this.slides.length > 1 ? this.previousSlideButton.focus() : (e = h(this.modalEl).at(0)) == null || e.focus());
    }, this.onPreviousSlideClick = () => {
      var e;
      this.activateSlide(Math.max(0, this.activeSlideIndex - 1)), this.activeSlideIndex === 0 && (this.slides.length > 1 ? this.nextSlideButton.focus() : (e = h(this.modalEl).at(0)) == null || e.focus());
    }, this.registerSlides = () => {
      this.removeSlideListeners(), this.slides = Array.from(this.el.children).filter((e) => e.tagName === "SWIRL-FILE-VIEWER"), this.setSlideAttributes();
    }, this.onPointerDown = (e) => {
      this.slides.length <= 1 || (this.dragging = !0, this.dragStartPosition = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX, this.slides.forEach((i) => {
        i.style.transition = "none";
      }));
    }, this.onPointerMove = async (e) => {
      var a, n;
      if (!this.dragging)
        return;
      const i = !(e instanceof MouseEvent) && e.touches.length > 1, s = (n = (a = this.slides[this.activeSlideIndex]) == null ? void 0 : a.shadowRoot) == null ? void 0 : n.querySelector("swirl-file-viewer-image"), l = Boolean(s) ? await s.getZoom() > 1 : !1;
      if (i || l)
        return;
      e.preventDefault();
      const c = e instanceof MouseEvent ? e.clientX - this.dragStartPosition : e.touches[0].clientX - this.dragStartPosition;
      this.slides.forEach((d) => {
        const b = this.activeSlideIndex * d.getBoundingClientRect().width;
        this.dragDelta = c, d.style.transform = `translate3d(${(-b + this.dragDelta) / 16}rem, 0, 0)`;
      });
    }, this.onPointerUp = () => {
      if (!this.dragging)
        return;
      this.dragging = !1, this.dragStartPosition = void 0;
      const e = this.dragDelta / this.slides[this.activeSlideIndex].getBoundingClientRect().width;
      this.dragDelta = 0;
      const i = e > 0.2, s = e < -0.2;
      this.slides.forEach((l) => {
        l.style.transition = "";
      }), i ? this.onPreviousSlideClick() : s ? this.onNextSlideClick() : this.resetSlidePositions();
    }, this.onBackdropClick = (e) => {
      e.target === this.slidesContainer && this.close();
    }, this.onContextMenu = (e) => {
      this.downloadButtonEnabled || e.preventDefault();
    };
  }
  connectedCallback() {
    this.componentLoaded && this.registerSlides();
  }
  componentWillLoad() {
    this.registerSlides();
  }
  componentDidLoad() {
    this.ensureOpening(), this.setDialogCustomProps(), this.activateSlide(0), this.componentLoaded = !0;
  }
  disconnectedCallback() {
    var t;
    this.unlockBodyScroll(), this.removeSlideListeners(), this.activateSlideTimeout && clearTimeout(this.activateSlideTimeout), this.closingTimeout && clearTimeout(this.closingTimeout), (t = this.modalEl) != null && t.open && this.modalEl.close();
  }
  watchActiveSlideIndex() {
    this.activeSlideChange.emit(this.activeSlideIndex);
  }
  async open() {
    this.opening = !0, this.modalEl && (this.modalEl.showModal(), this.lockBodyScroll(), this.activateSlide(this.activeSlideIndex || 0));
  }
  async close() {
    this.closing || (this.closing = !0, this.unlockBodyScroll(), this.closingTimeout && (clearTimeout(this.closingTimeout), this.closingTimeout = void 0), this.closingTimeout = setTimeout(() => {
      this.resetImageZoom(), this.stopAllMediaPlayers(), this.modalEl.close(), this.closing = !1, this.lightboxClose.emit();
    }, 150));
  }
  async activateSlide(t) {
    this.dragging = !1, this.activeSlideIndex = t, this.slides.forEach((e, i) => {
      i === this.activeSlideIndex ? (e.removeAttribute("aria-hidden"), e.setAttribute("active", "true")) : i === this.activeSlideIndex - 1 || i === this.activeSlideIndex + 1 ? (e.setAttribute("aria-hidden", "true"), e.setAttribute("active", "true")) : e.setAttribute("aria-hidden", "true"), e.style.transform = `translate3d(-${100 * this.activeSlideIndex}%, 0, 0)`;
    }), this.activateSlideTimeout && (clearTimeout(this.activateSlideTimeout), this.activateSlideTimeout = void 0), this.activateSlideTimeout = setTimeout(() => {
      this.slides.forEach((e, i) => {
        i !== this.activeSlideIndex && i !== this.activeSlideIndex - 1 && i !== this.activeSlideIndex + 1 && e.setAttribute("active", "false");
      });
    }, 300), this.stopAllMediaPlayers(), this.resetImageZoom();
  }
  ensureOpening() {
    var t;
    this.opening && !((t = this.modalEl) != null && t.open) && this.open();
  }
  setDialogCustomProps() {
    this.modalEl.setAttribute("closedby", "none");
  }
  setSlideAttributes() {
    this.slides.forEach((t) => {
      t.setAttribute("active", "false"), t.setAttribute("aria-label", t.file), t.setAttribute("aria-roledescription", "slide"), t.setAttribute("role", "group"), t.addEventListener("dragstart", this.preventDragStart);
    });
  }
  removeSlideListeners() {
    var t;
    (t = this.slides) == null || t.forEach((e) => {
      e.removeEventListener("dragstart", this.preventDragStart);
    });
  }
  resetSlidePositions() {
    this.slides.forEach((t) => {
      t.style.transform = `translate3d(-${100 * this.activeSlideIndex}%, 0, 0)`;
    });
  }
  lockBodyScroll() {
    x(this.el);
  }
  unlockBodyScroll() {
    m(this.el);
  }
  getMediaPlayers() {
    return v(this.el, "video");
  }
  stopAllMediaPlayers() {
    this.getMediaPlayers().forEach((t) => t.pause());
  }
  resetImageZoom() {
    this.slides.forEach((t) => {
      var i;
      const e = (i = t == null ? void 0 : t.shadowRoot) == null ? void 0 : i.querySelector("swirl-file-viewer-image");
      Boolean(e) && e.resetZoom();
    });
  }
  render() {
    const t = this.slides.length > 1, e = p("lightbox", {
      "lightbox--closing": this.closing
    });
    return o(u, { key: "dec00df0429b06410d336d261f13cd8c4210feb4" }, o("dialog", { key: "65a5a1f17aa31259b78ef1d2cc6b4d6f83b53051", "aria-label": this.label, class: e, id: "lightbox", onKeyDown: this.onKeyDown, onMouseDown: this.onPointerDown, onMouseMove: this.onPointerMove, onMouseOut: this.onPointerUp, onMouseUp: this.onPointerUp, onTouchEnd: this.onPointerUp, onTouchMove: this.onPointerMove, onTouchStart: this.onPointerDown, ref: (i) => this.modalEl = i }, o("div", { key: "575206d15ec2ea22eaa2cb294eda5c493b2ca1f0", class: "lightbox__body", role: "document" }, o("header", { key: "e1843898181296ea568cb868ee22b6b678ea1cef", class: "lightbox__header" }, o("div", { key: "a39846ea8d687db8167ea2cde6da885cddee2c96", class: "lightbox__toolbar" }, o("slot", { key: "51db02a499682b3052cb685c40316b6f22a3d4bf", name: "toolbar" }), this.downloadButtonEnabled && o("button", { key: "2a83cdead0eee85b8745697195f5d2a09889c59f", "aria-label": this.downloadButtonLabel, class: "lightbox__download-button", onClick: this.onDownloadButtonClick, type: "button" }, o("swirl-icon-download", { key: "35ae56767e8edbbd0567dbd2f54d0537038982bf" }))), o("button", { key: "b26ee336969968d044b0b2f00f51a85eb2d22b20", "aria-label": this.closeButtonLabel, class: "lightbox__close-button", onClick: this.onCloseButtonClick, type: "button" }, o("swirl-icon-close", { key: "73226a57e4f58793af48c0000f74447f9ceb1686" }))), o("div", { key: "bbdf47ecb38e1f3f0ac7ea0f5a147c4be821f323", "aria-roledescription": "carousel", class: "lightbox__content", role: "group" }, o("div", { key: "3ca670e4ffe10b508e752401c5334cc45b095605", "aria-atomic": "false", "aria-live": "polite", class: "lightbox__slides", onClick: this.onBackdropClick, onContextMenu: this.onContextMenu, ref: (i) => this.slidesContainer = i }, o("slot", { key: "5fe406e445cb425820824f67db88bcb0ff345148", onSlotchange: this.registerSlides }))), o("div", { key: "dcd7de95f9996a16a20e695bd84768948459e779", class: "lightbox__controls" }, o("button", { key: "bd7e44636ed63a1d07a943e45961f3407b1b479c", "aria-label": this.previousSlideButtonLabel, class: "lightbox__previous-slide-button", disabled: this.activeSlideIndex === 0, onClick: this.onPreviousSlideClick, ref: (i) => this.previousSlideButton = i }, o("swirl-icon-arrow-left", { key: "17884c850ffa3a01ba6572010ecc4453713b57b0" })), o("button", { key: "f9904cd4c7643ec3be856278c3b10c6db1078cce", "aria-label": this.nextSlideButtonLabel, class: "lightbox__next-slide-button", disabled: this.activeSlideIndex === this.slides.length - 1, onClick: this.onNextSlideClick, ref: (i) => this.nextSlideButton = i }, o("swirl-icon-arrow-right", { key: "efbddd2819f717d99974600dd0773b00ef629024" }))), t && o("span", { key: "c5998e245d764ba735d0d7f5748e7e19f8526eb9", class: "lightbox__pagination" }, o("span", { key: "1e38e7ed072c74e1251cdc1a4c83b4499742f0b4", "aria-current": "page" }, this.activeSlideIndex + 1), " /", " ", this.slides.length))));
  }
  get el() {
    return f(this);
  }
  static get watchers() {
    return {
      activeSlideIndex: [{
        watchActiveSlideIndex: 0
      }]
    };
  }
};
_.style = S();
export {
  _ as swirl_lightbox
};
