import { defineComponent as F, inject as b, reactive as j, ref as c, h as w, provide as M, onMounted as Le, nextTick as Ie, onUnmounted as Ee, computed as D, watch as oe, cloneVNode as ke, Fragment as B, useAttrs as je, useCssModule as Be, openBlock as A, createElementBlock as E, createVNode as De, mergeProps as Re, unref as N, withCtx as G, renderList as le, createBlock as W, renderSlot as Pe, createElementVNode as Ve, normalizeClass as ie, createCommentVNode as Ae } from "vue";
import { t as V } from "./locale.js";
import Ue from "./Thumbnail.js";
import $e from "./ThumbnailGroup.js";
import { _ as ze } from "./_plugin-vue_export-helper-CHgC5LLL.js";
/**
 * Vue 3 Carousel 0.3.4
 * (c) 2024
 * @license MIT
 */
const f = {
  itemsToShow: 1,
  itemsToScroll: 1,
  modelValue: 0,
  transition: 300,
  autoplay: 0,
  snapAlign: "center",
  wrapAround: !1,
  throttle: 16,
  pauseAutoplayOnHover: !1,
  mouseDrag: !0,
  touchDrag: !0,
  dir: "ltr",
  breakpoints: void 0,
  i18n: {
    ariaNextSlide: "Navigate to next slide",
    ariaPreviousSlide: "Navigate to previous slide",
    ariaNavigateToSlide: "Navigate to slide {slideNumber}",
    ariaGallery: "Gallery",
    itemXofY: "Item {currentSlide} of {slidesCount}",
    iconArrowUp: "Arrow pointing upwards",
    iconArrowDown: "Arrow pointing downwards",
    iconArrowRight: "Arrow pointing to the right",
    iconArrowLeft: "Arrow pointing to the left"
  }
}, Ce = {
  // count of items to showed per view
  itemsToShow: {
    default: f.itemsToShow,
    type: Number
  },
  // count of items to be scrolled
  itemsToScroll: {
    default: f.itemsToScroll,
    type: Number
  },
  // control infinite scrolling mode
  wrapAround: {
    default: f.wrapAround,
    type: Boolean
  },
  // control max drag
  throttle: {
    default: f.throttle,
    type: Number
  },
  // control snap position alignment
  snapAlign: {
    default: f.snapAlign,
    validator(e) {
      return ["start", "end", "center", "center-even", "center-odd"].includes(e);
    }
  },
  // sliding transition time in ms
  transition: {
    default: f.transition,
    type: Number
  },
  // an object to store breakpoints
  breakpoints: {
    default: f.breakpoints,
    type: Object
  },
  // time to auto advance slides in ms
  autoplay: {
    default: f.autoplay,
    type: Number
  },
  // pause autoplay when mouse hover over the carousel
  pauseAutoplayOnHover: {
    default: f.pauseAutoplayOnHover,
    type: Boolean
  },
  // slide number number of initial slide
  modelValue: {
    default: void 0,
    type: Number
  },
  // toggle mouse dragging.
  mouseDrag: {
    default: f.mouseDrag,
    type: Boolean
  },
  // toggle mouse dragging.
  touchDrag: {
    default: f.touchDrag,
    type: Boolean
  },
  // control snap position alignment
  dir: {
    default: f.dir,
    validator(e) {
      return ["rtl", "ltr"].includes(e);
    }
  },
  // aria-labels and additional text labels
  i18n: {
    default: f.i18n,
    type: Object
  },
  // an object to pass all settings
  settings: {
    default() {
      return {};
    },
    type: Object
  }
};
function Xe({ config: e, slidesCount: n }) {
  const { snapAlign: t, wrapAround: o, itemsToShow: r = 1 } = e;
  if (o)
    return Math.max(n - 1, 0);
  let i;
  switch (t) {
    case "start":
      i = n - r;
      break;
    case "end":
      i = n - 1;
      break;
    case "center":
    case "center-odd":
      i = n - Math.ceil((r - 0.5) / 2);
      break;
    case "center-even":
      i = n - Math.ceil(r / 2);
      break;
    default:
      i = 0;
      break;
  }
  return Math.max(i, 0);
}
function He({ config: e, slidesCount: n }) {
  const { wrapAround: t, snapAlign: o, itemsToShow: r = 1 } = e;
  let i = 0;
  if (t || r > n)
    return i;
  switch (o) {
    case "start":
      i = 0;
      break;
    case "end":
      i = r - 1;
      break;
    case "center":
    case "center-odd":
      i = Math.floor((r - 1) / 2);
      break;
    case "center-even":
      i = Math.floor((r - 2) / 2);
      break;
    default:
      i = 0;
      break;
  }
  return i;
}
function re({ val: e, max: n, min: t }) {
  return n < t ? e : Math.min(Math.max(e, t), n);
}
function Ye({ config: e, currentSlide: n, slidesCount: t }) {
  const { snapAlign: o, wrapAround: r, itemsToShow: i = 1 } = e;
  let d = n;
  switch (o) {
    case "center":
    case "center-odd":
      d -= (i - 1) / 2;
      break;
    case "center-even":
      d -= (i - 2) / 2;
      break;
    case "end":
      d -= i - 1;
      break;
  }
  return r ? d : re({
    val: d,
    max: t - i,
    min: 0
  });
}
function _e(e) {
  return e ? e.reduce((n, t) => {
    var o;
    return t.type === B ? [...n, ..._e(t.children)] : ((o = t.type) === null || o === void 0 ? void 0 : o.name) === "CarouselSlide" ? [...n, t] : n;
  }, []) : [];
}
function se({ val: e, max: n, min: t = 0 }) {
  return e > n ? se({ val: e - (n + 1), max: n, min: t }) : e < t ? se({ val: e + (n + 1), max: n, min: t }) : e;
}
function Ge(e, n) {
  let t;
  return n ? function(...o) {
    const r = this;
    t || (e.apply(r, o), t = !0, setTimeout(() => t = !1, n));
  } : e;
}
function We(e, n) {
  let t;
  return function(...o) {
    t && clearTimeout(t), t = setTimeout(() => {
      e(...o), t = null;
    }, n);
  };
}
function Fe(e = "", n = {}) {
  return Object.entries(n).reduce((t, [o, r]) => t.replace(`{${o}}`, String(r)), e);
}
var qe = F({
  name: "ARIA",
  setup() {
    const e = b("config", j(Object.assign({}, f))), n = b("currentSlide", c(0)), t = b("slidesCount", c(0));
    return () => w("div", {
      class: ["carousel__liveregion", "carousel__sr-only"],
      "aria-live": "polite",
      "aria-atomic": "true"
    }, Fe(e.i18n.itemXofY, {
      currentSlide: n.value + 1,
      slidesCount: t.value
    }));
  }
}), Je = F({
  name: "Carousel",
  props: Ce,
  setup(e, { slots: n, emit: t, expose: o }) {
    var r;
    const i = c(null), d = c([]), p = c(0), s = c(0), l = j(Object.assign({}, f));
    let g = Object.assign({}, f), y;
    const u = c((r = e.modelValue) !== null && r !== void 0 ? r : 0), C = c(0), m = c(0), x = c(0), S = c(0);
    let k, q;
    M("config", l), M("slidesCount", s), M("currentSlide", u), M("maxSlide", x), M("minSlide", S), M("slideWidth", p);
    function J() {
      y = Object.assign({}, e.breakpoints), g = Object.assign(Object.assign(Object.assign({}, g), e), { i18n: Object.assign(Object.assign({}, g.i18n), e.i18n), breakpoints: void 0 }), de(g);
    }
    function U() {
      if (!y || !Object.keys(y).length)
        return;
      const a = Object.keys(y).map((v) => Number(v)).sort((v, _) => +_ - +v);
      let h = Object.assign({}, g);
      a.some((v) => {
        const _ = window.matchMedia(`(min-width: ${v}px)`).matches;
        return _ && (h = Object.assign(Object.assign({}, h), y[v])), _;
      }), de(h);
    }
    function de(a) {
      Object.entries(a).forEach(([h, v]) => l[h] = v);
    }
    const ve = We(() => {
      U(), $(), R();
    }, 16);
    function R() {
      if (!i.value)
        return;
      const a = i.value.getBoundingClientRect();
      p.value = a.width / l.itemsToShow;
    }
    function $() {
      s.value <= 0 || (m.value = Math.ceil((s.value - 1) / 2), x.value = Xe({ config: l, slidesCount: s.value }), S.value = He({ config: l, slidesCount: s.value }), l.wrapAround || (u.value = re({
        val: u.value,
        max: x.value,
        min: S.value
      })));
    }
    Le(() => {
      Ie(() => R()), setTimeout(() => R(), 1e3), U(), ge(), window.addEventListener("resize", ve, { passive: !0 }), t("init");
    }), Ee(() => {
      q && clearTimeout(q), k && clearInterval(k), window.removeEventListener("resize", ve, {
        passive: !0
      });
    });
    let T = !1;
    const z = { x: 0, y: 0 }, X = { x: 0, y: 0 }, O = j({ x: 0, y: 0 }), H = c(!1), K = c(!1), Me = () => {
      H.value = !0;
    }, Ne = () => {
      H.value = !1;
    };
    function fe(a) {
      ["INPUT", "TEXTAREA", "SELECT"].includes(a.target.tagName) || (T = a.type === "touchstart", T || a.preventDefault(), !(!T && a.button !== 0 || L.value) && (z.x = T ? a.touches[0].clientX : a.clientX, z.y = T ? a.touches[0].clientY : a.clientY, document.addEventListener(T ? "touchmove" : "mousemove", me, !0), document.addEventListener(T ? "touchend" : "mouseup", pe, !0)));
    }
    const me = Ge((a) => {
      K.value = !0, X.x = T ? a.touches[0].clientX : a.clientX, X.y = T ? a.touches[0].clientY : a.clientY;
      const h = X.x - z.x, v = X.y - z.y;
      O.y = v, O.x = h;
    }, l.throttle);
    function pe() {
      const a = l.dir === "rtl" ? -1 : 1, h = Math.sign(O.x) * 0.4, v = Math.round(O.x / p.value + h) * a;
      if (v && !T) {
        const _ = (Te) => {
          window.removeEventListener("click", _, !0);
        };
        window.addEventListener("click", _, !0);
      }
      I(u.value - v), O.x = 0, O.y = 0, K.value = !1, document.removeEventListener(T ? "touchmove" : "mousemove", me, !0), document.removeEventListener(T ? "touchend" : "mouseup", pe, !0);
    }
    function ge() {
      !l.autoplay || l.autoplay <= 0 || (k = setInterval(() => {
        l.pauseAutoplayOnHover && H.value || Y();
      }, l.autoplay));
    }
    function he() {
      k && (clearInterval(k), k = null), ge();
    }
    const L = c(!1);
    function I(a) {
      const h = l.wrapAround ? a : re({
        val: a,
        max: x.value,
        min: S.value
      });
      u.value === h || L.value || (t("slide-start", {
        slidingToIndex: a,
        currentSlideIndex: u.value,
        prevSlideIndex: C.value,
        slidesCount: s.value
      }), L.value = !0, C.value = u.value, u.value = h, q = setTimeout(() => {
        if (l.wrapAround) {
          const v = se({
            val: h,
            max: x.value,
            min: 0
          });
          v !== u.value && (u.value = v, t("loop", {
            currentSlideIndex: u.value,
            slidingToIndex: a
          }));
        }
        t("update:modelValue", u.value), t("slide-end", {
          currentSlideIndex: u.value,
          prevSlideIndex: C.value,
          slidesCount: s.value
        }), L.value = !1, he();
      }, l.transition));
    }
    function Y() {
      I(u.value + l.itemsToScroll);
    }
    function Q() {
      I(u.value - l.itemsToScroll);
    }
    const Se = { slideTo: I, next: Y, prev: Q };
    M("nav", Se), M("isSliding", L);
    const be = D(() => Ye({
      config: l,
      currentSlide: u.value,
      slidesCount: s.value
    }));
    M("slidesToScroll", be);
    const Oe = D(() => {
      const a = l.dir === "rtl" ? -1 : 1, h = be.value * p.value * a;
      return {
        transform: `translateX(${O.x - h}px)`,
        transition: `${L.value ? l.transition : 0}ms`,
        margin: l.wrapAround ? `0 -${s.value * p.value}px` : "",
        width: "100%"
      };
    });
    function we() {
      J(), U(), $(), R(), he();
    }
    Object.keys(Ce).forEach((a) => {
      ["modelValue"].includes(a) || oe(() => e[a], we);
    }), oe(() => e.modelValue, (a) => {
      a !== u.value && I(Number(a));
    }), oe(s, $), t("before-init"), J();
    const ye = {
      config: l,
      slidesCount: s,
      slideWidth: p,
      next: Y,
      prev: Q,
      slideTo: I,
      currentSlide: u,
      maxSlide: x,
      minSlide: S,
      middleSlide: m
    };
    o({
      updateBreakpointsConfigs: U,
      updateSlidesData: $,
      updateSlideWidth: R,
      initDefaultConfigs: J,
      restartCarousel: we,
      slideTo: I,
      next: Y,
      prev: Q,
      nav: Se,
      data: ye
    });
    const Z = n.default || n.slides, ee = n.addons, xe = j(ye);
    return () => {
      const a = _e(Z == null ? void 0 : Z(xe)), h = (ee == null ? void 0 : ee(xe)) || [];
      a.forEach((te, ne) => te.props.index = ne);
      let v = a;
      if (l.wrapAround) {
        const te = a.map((ae, P) => ke(ae, {
          index: -a.length + P,
          isClone: !0,
          key: `clone-before-${P}`
        })), ne = a.map((ae, P) => ke(ae, {
          index: a.length + P,
          isClone: !0,
          key: `clone-after-${P}`
        }));
        v = [...te, ...a, ...ne];
      }
      d.value = a, s.value = Math.max(a.length, 1);
      const _ = w("ol", {
        class: "carousel__track",
        style: Oe.value,
        onMousedownCapture: l.mouseDrag ? fe : null,
        onTouchstartPassiveCapture: l.touchDrag ? fe : null
      }, v), Te = w("div", { class: "carousel__viewport" }, _);
      return w("section", {
        ref: i,
        class: {
          carousel: !0,
          "is-sliding": L.value,
          "is-dragging": K.value,
          "is-hover": H.value,
          "carousel--rtl": l.dir === "rtl"
        },
        dir: l.dir,
        "aria-label": l.i18n.ariaGallery,
        tabindex: "0",
        onMouseenter: Me,
        onMouseleave: Ne
      }, [Te, h, w(qe)]);
    };
  }
}), ue;
(function(e) {
  e.arrowUp = "arrowUp", e.arrowDown = "arrowDown", e.arrowRight = "arrowRight", e.arrowLeft = "arrowLeft";
})(ue || (ue = {}));
const Ke = {
  arrowUp: "M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z",
  arrowDown: "M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z",
  arrowRight: "M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z",
  arrowLeft: "M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"
};
function Qe(e) {
  return e in ue;
}
const ce = (e) => {
  const n = b("config", j(Object.assign({}, f))), t = String(e.name), o = `icon${t.charAt(0).toUpperCase() + t.slice(1)}`;
  if (!t || typeof t != "string" || !Qe(t))
    return;
  const r = Ke[t], i = w("path", { d: r }), d = n.i18n[o] || e.title || t, p = w("title", d);
  return w("svg", {
    class: "carousel__icon",
    viewBox: "0 0 24 24",
    role: "img",
    "aria-label": d
  }, [p, i]);
};
ce.props = { name: String, title: String };
const Ze = (e, { slots: n, attrs: t }) => {
  const { next: o, prev: r } = n || {}, i = b("config", j(Object.assign({}, f))), d = b("maxSlide", c(1)), p = b("minSlide", c(1)), s = b("currentSlide", c(1)), l = b("nav", {}), { dir: g, wrapAround: y, i18n: u } = i, C = g === "rtl", m = w("button", {
    type: "button",
    class: [
      "carousel__prev",
      !y && s.value <= p.value && "carousel__prev--disabled",
      t == null ? void 0 : t.class
    ],
    "aria-label": u.ariaPreviousSlide,
    onClick: l.prev
  }, (r == null ? void 0 : r()) || w(ce, { name: C ? "arrowRight" : "arrowLeft" })), x = w("button", {
    type: "button",
    class: [
      "carousel__next",
      !y && s.value >= d.value && "carousel__next--disabled",
      t == null ? void 0 : t.class
    ],
    "aria-label": u.ariaNextSlide,
    onClick: l.next
  }, (o == null ? void 0 : o()) || w(ce, { name: C ? "arrowLeft" : "arrowRight" }));
  return [m, x];
};
var et = F({
  name: "CarouselSlide",
  props: {
    index: {
      type: Number,
      default: 1
    },
    isClone: {
      type: Boolean,
      default: !1
    }
  },
  setup(e, { slots: n }) {
    const t = b("config", j(Object.assign({}, f))), o = b("currentSlide", c(0)), r = b("slidesToScroll", c(0)), i = b("isSliding", c(!1)), d = D(() => e.index === o.value), p = D(() => e.index === o.value - 1), s = D(() => e.index === o.value + 1), l = D(() => {
      const g = Math.floor(r.value), y = Math.ceil(r.value + t.itemsToShow - 1);
      return e.index >= g && e.index <= y;
    });
    return () => {
      var g;
      return w("li", {
        style: { width: `${100 / t.itemsToShow}%` },
        class: {
          carousel__slide: !0,
          "carousel__slide--clone": e.isClone,
          "carousel__slide--visible": l.value,
          "carousel__slide--active": d.value,
          "carousel__slide--prev": p.value,
          "carousel__slide--next": s.value,
          "carousel__slide--sliding": i.value
        },
        "aria-hidden": !l.value
      }, (g = n.default) === null || g === void 0 ? void 0 : g.call(n, {
        isActive: d.value,
        isClone: e.isClone,
        isPrev: p.value,
        isNext: s.value,
        isSliding: i.value,
        isVisible: l.value
      }));
    };
  }
});
const tt = ["src", "title"], nt = /* @__PURE__ */ F({
  inheritAttrs: !1,
  __name: "Carousel",
  props: {
    slides: {},
    autoplayInterval: { default: 0 },
    hideNavigation: { type: Boolean, default: !1 },
    hidePagination: { type: Boolean, default: !1 },
    itemsToScroll: { default: 1 },
    itemsToShow: { default: 1 },
    loop: { type: Boolean, default: !1 },
    pagination: { default: "tile" },
    paginationTileRadius: { default: "standard" },
    pauseAutoplayOnHover: { type: Boolean, default: !1 },
    roundBorders: { type: Boolean, default: !1 },
    staticPaginationDots: { type: Boolean, default: !1 }
  },
  emits: ["click", "transition", "transition:multi"],
  setup(e, { expose: n, emit: t }) {
    const o = e, r = je(), i = Be(), d = c(), p = t, s = c(0);
    function l(...m) {
      const [x] = m;
      x !== void 0 && g(x);
    }
    const g = (m) => {
      s.value = m;
    }, y = () => {
      C();
    }, u = () => {
      p("click", o.slides[s.value]);
    }, C = () => {
      if (o.itemsToShow === 1) {
        p("transition", o.slides[s.value]);
        return;
      }
      const m = o.slides.slice(s.value, s.value + o.itemsToShow);
      p("transition:multi", m);
    };
    return n({
      next: () => {
        var m;
        return (m = d.value) == null ? void 0 : m.next();
      },
      prev: () => {
        var m;
        return (m = d.value) == null ? void 0 : m.prev();
      },
      slideTo: g
    }), (m, x) => (A(), E(B, null, [
      De(Je, Re({
        ref_key: "carouselRef",
        ref: d,
        "model-value": s.value,
        "aria-live": "polite",
        "aria-roledescription": "carousel",
        class: ["stash-carousel mb-6", N(i).root],
        "data-test": "stash-carousel",
        autoplay: e.autoplayInterval,
        i18n: {
          ariaNextSlide: N(V)("ll.next"),
          ariaPreviousSlide: N(V)("ll.previous"),
          iconArrowLeft: N(V)("ll.previous"),
          iconArrowRight: N(V)("ll.next")
        },
        "items-to-scroll": o.itemsToScroll,
        "items-to-show": o.itemsToShow,
        "pause-autoplay-on-hover": e.pauseAutoplayOnHover,
        "wrap-around": o.loop
      }, N(r), {
        onInit: y,
        onSlideEnd: C,
        "onUpdate:modelValue": l
      }), {
        addons: G(() => [
          o.slides.length > 1 && !o.hideNavigation ? (A(), W(Ze, { key: 0 })) : Ae("", !0)
        ]),
        default: G(() => [
          (A(!0), E(B, null, le(o.slides, (S, k) => (A(), W(et, {
            key: S.id,
            "data-test": "stash-carousel|slide",
            class: "cursor-pointer",
            onClick: u
          }, {
            default: G(() => [
              Pe(m.$slots, "slide", {
                slide: S,
                index: k
              }, () => [
                Ve("img", {
                  class: ie(["size-full", [{ rounded: o.roundBorders }]]),
                  src: S.imageUrl,
                  title: N(V)("ll.carousel.imageLabel", {
                    index: k + 1,
                    total: e.slides.length
                  })
                }, null, 10, tt)
              ])
            ]),
            _: 2
          }, 1024))), 128))
        ]),
        _: 3
      }, 16, ["model-value", "autoplay", "class", "i18n", "items-to-scroll", "items-to-show", "pause-autoplay-on-hover", "wrap-around"]),
      o.hidePagination ? Ae("", !0) : (A(), E(B, { key: 0 }, [
        o.pagination === "tile" ? (A(), W($e, {
          key: 0,
          "active-thumbnail": s.value,
          thumbnails: e.slides,
          radius: o.paginationTileRadius === "full" ? "circle" : "rounded",
          "onUpdate:activeThumbnail": g
        }, {
          default: G(() => [
            (A(!0), E(B, null, le(e.slides, (S) => (A(), W(Ue, {
              key: S.id,
              thumbnail: S,
              variant: "translucent"
            }, null, 8, ["thumbnail"]))), 128))
          ]),
          _: 1
        }, 8, ["active-thumbnail", "thumbnails", "radius"])) : (A(), E("ul", {
          key: 1,
          class: ie(["text-center", [!e.staticPaginationDots && "lg:hidden"]]),
          "data-test": "stash-carousel|pagination-dots"
        }, [
          (A(!0), E(B, null, le(e.slides, (S, k) => (A(), E("li", {
            key: S.imageUrl,
            class: ie(["inline-block rounded-full", [N(i)["pagination-dot"], [s.value === k ? "bg-blue-500" : "bg-blue-100"]]])
          }, null, 2))), 128))
        ], 2))
      ], 64))
    ], 64));
  }
}), at = "_root_Ss9t_", ot = {
  root: at,
  "pagination-dot": "_pagination-dot_knLVs"
}, lt = {
  $style: ot
}, dt = /* @__PURE__ */ ze(nt, [["__cssModules", lt]]);
export {
  dt as default
};
//# sourceMappingURL=Carousel.js.map
