import { a as x } from "../../../../@react-spring/web/dist/react-spring-web.esm.mjs";
import { useDrag as b } from "../../../../@use-gesture/react/dist/use-gesture-react.esm.mjs";
import s, { forwardRef as R, useImperativeHandle as w, useRef as I } from "react";
import { bound as c } from "../../utils/bound.mjs";
import { convertPx as M } from "../../utils/convert-px.mjs";
import { Slide as $ } from "./slide.mjs";
import { useSpring as y } from "../../../../@react-spring/core/dist/react-spring-core.esm.mjs";
const f = "adm-image-viewer", _ = R((o, g) => {
  const n = window.innerWidth + M(16), [{
    x: r
  }, d] = y(() => ({
    x: o.defaultIndex * n,
    config: {
      tension: 250,
      clamp: !0
    }
  })), m = o.images.length;
  function l(e, t = !1) {
    var i;
    const a = c(e, 0, m - 1);
    (i = o.onIndexChange) === null || i === void 0 || i.call(o, a), d.start({
      x: a * n,
      immediate: t
    });
  }
  w(g, () => ({
    swipeTo: l
  }));
  const u = I(!1), h = b((e) => {
    if (u.current)
      return;
    const [t] = e.offset;
    if (e.last) {
      const i = Math.floor(t / n), a = i + 1, v = Math.min(e.velocity[0] * 2e3, n) * e.direction[0];
      l(c(Math.round((t + v) / n), i, a));
    } else
      d.start({
        x: t,
        immediate: !0
      });
  }, {
    transform: ([e, t]) => [-e, t],
    from: () => [r.get(), 0],
    bounds: () => ({
      left: 0,
      right: (m - 1) * n
    }),
    rubberband: !0,
    axis: "x",
    pointer: {
      touch: !0
    }
  });
  return s.createElement("div", Object.assign({
    className: `${f}-slides`
  }, h()), s.createElement(x.div, {
    className: `${f}-indicator`
  }, r.to((e) => `${c(Math.round(e / n), 0, m - 1) + 1} / ${m}`)), s.createElement(x.div, {
    className: `${f}-slides-inner`,
    style: {
      x: r.to((e) => -e)
    }
  }, o.images.map((e, t) => s.createElement($, {
    key: t,
    image: e,
    onTap: o.onTap,
    maxZoom: o.maxZoom,
    imageRender: o.imageRender,
    index: t,
    onZoomChange: (i) => {
      if (i !== 1) {
        const a = Math.round(r.get() / n);
        d.start({
          x: a * n
        });
      }
    },
    dragLockRef: u
  }))));
});
export {
  _ as Slides
};
