import le from "../../@babel/runtime/helpers/esm/extends.mjs";
import i from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import me from "../../@babel/runtime/helpers/esm/typeof.mjs";
import G from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import V from "../../rc-util/es/hooks/useMergedState.mjs";
import * as t from "react";
import { useState as y } from "react";
import { PreviewGroupContext as ue } from "./context.mjs";
import ce from "./hooks/usePreviewItems.mjs";
import ve from "./Preview.mjs";
var de = ["visible", "onVisibleChange", "getContainer", "current", "movable", "minScale", "maxScale", "countRender", "closeIcon", "onChange", "onTransform", "toolbarRender", "imageRender"], fe = ["src"], _e = function(r) {
  var m, f = r.previewPrefixCls, E = f === void 0 ? "rc-image-preview" : f, $ = r.children, g = r.icons, j = g === void 0 ? {} : g, O = r.items, p = r.preview, A = r.fallback, e = me(p) === "object" ? p : {}, C = e.visible, u = e.onVisibleChange, F = e.getContainer, K = e.current, W = e.movable, q = e.minScale, z = e.maxScale, B = e.countRender, D = e.closeIcon, c = e.onChange, H = e.onTransform, J = e.toolbarRender, L = e.imageRender, N = G(e, de), Q = ce(O), P = i(Q, 2), a = P[0], b = P[1], U = V(0, {
    value: K
  }), w = i(U, 2), v = w[0], d = w[1], X = y(!1), S = i(X, 2), Y = S[0], x = S[1], h = ((m = a[v]) === null || m === void 0 ? void 0 : m.data) || {}, Z = h.src, ee = G(h, fe), re = V(!!C, {
    value: C,
    onChange: function(o, n) {
      u == null || u(o, n, v);
    }
  }), I = i(re, 2), s = I[0], _ = I[1], oe = y(null), R = i(oe, 2), ne = R[0], M = R[1], k = t.useCallback(function(l, o, n) {
    var T = a.findIndex(function(se) {
      return se.id === l;
    });
    _(!0), M({
      x: o,
      y: n
    }), d(T < 0 ? 0 : T), x(!0);
  }, [a]);
  t.useEffect(function() {
    s ? Y || d(0) : x(!1);
  }, [s]);
  var ie = function(o, n) {
    d(o), c == null || c(o, n);
  }, te = function() {
    _(!1), M(null);
  }, ae = t.useMemo(function() {
    return {
      register: b,
      onPreview: k
    };
  }, [b, k]);
  return /* @__PURE__ */ t.createElement(ue.Provider, {
    value: ae
  }, $, /* @__PURE__ */ t.createElement(ve, le({
    "aria-hidden": !s,
    movable: W,
    visible: s,
    prefixCls: E,
    closeIcon: D,
    onClose: te,
    mousePosition: ne,
    imgCommonProps: ee,
    src: Z,
    fallback: A,
    icons: j,
    minScale: q,
    maxScale: z,
    getContainer: F,
    current: v,
    count: a.length,
    countRender: B,
    onTransform: H,
    toolbarRender: J,
    imageRender: L,
    onChange: ie
  }, N)));
};
export {
  _e as default
};
