import p from "../../@babel/runtime/helpers/esm/extends.mjs";
import v from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import q from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import h from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import xe from "../../@babel/runtime/helpers/esm/typeof.mjs";
import z from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import P from "../../classnames/index.mjs";
import { getOffset as Ne } from "../../rc-util/es/Dom/css.mjs";
import ke from "../../rc-util/es/hooks/useMergedState.mjs";
import * as i from "react";
import { useState as ye, useContext as Re, useMemo as B } from "react";
import { COMMON_PROPS as H } from "./common.mjs";
import { PreviewGroupContext as Ee } from "./context.mjs";
import Ie from "./hooks/useRegisterImage.mjs";
import Me from "./hooks/useStatus.mjs";
import Oe from "./Preview.mjs";
import $e from "./PreviewGroup.mjs";
var Ve = ["src", "alt", "onPreviewClose", "prefixCls", "previewPrefixCls", "placeholder", "fallback", "width", "height", "style", "preview", "className", "onClick", "onError", "wrapperClassName", "wrapperStyle", "rootClassName"], je = ["src", "visible", "onVisibleChange", "getContainer", "mask", "maskClassName", "movable", "icons", "scaleStep", "minScale", "maxScale", "imageRender", "toolbarRender"], J = function(e) {
  var S = e.src, K = e.alt, L = e.onPreviewClose, b = e.prefixCls, a = b === void 0 ? "rc-image" : b, _ = e.previewPrefixCls, Q = _ === void 0 ? "".concat(a, "-preview") : _, l = e.placeholder, x = e.fallback, N = e.width, d = e.height, n = e.style, k = e.preview, f = k === void 0 ? !0 : k, U = e.className, s = e.onClick, X = e.onError, Y = e.wrapperClassName, Z = e.wrapperStyle, y = e.rootClassName, ee = z(e, Ve), re = l && l !== !0, r = xe(f) === "object" ? f : {}, u = r.src, R = r.visible, E = R === void 0 ? void 0 : R, I = r.onVisibleChange, ae = I === void 0 ? L : I, M = r.getContainer, ie = M === void 0 ? void 0 : M, O = r.mask, te = r.maskClassName, oe = r.movable, le = r.icons, ne = r.scaleStep, se = r.minScale, me = r.maxScale, ce = r.imageRender, ve = r.toolbarRender, de = z(r, je), C = u ?? S, fe = ke(!!E, {
    value: E,
    onChange: ae
  }), $ = h(fe, 2), V = $[0], j = $[1], ue = Me({
    src: S,
    isCustomPlaceholder: re,
    fallback: x
  }), g = h(ue, 3), Ce = g[0], ge = g[1], G = g[2], we = ye(null), A = h(we, 2), pe = A[0], D = A[1], w = Re(Ee), m = !!f, he = function() {
    j(!1), D(null);
  }, Pe = P(a, Y, y, q({}, "".concat(a, "-error"), G === "error")), c = B(function() {
    var t = {};
    return H.forEach(function(o) {
      e[o] !== void 0 && (t[o] = e[o]);
    }), t;
  }, H.map(function(t) {
    return e[t];
  })), Se = B(function() {
    return v(v({}, c), {}, {
      src: C
    });
  }, [C, c]), be = Ie(m, Se), _e = function(o) {
    var F = Ne(o.target), T = F.left, W = F.top;
    w ? w.onPreview(be, T, W) : (D({
      x: T,
      y: W
    }), j(!0)), s == null || s(o);
  };
  return /* @__PURE__ */ i.createElement(i.Fragment, null, /* @__PURE__ */ i.createElement("div", p({}, ee, {
    className: Pe,
    onClick: m ? _e : s,
    style: v({
      width: N,
      height: d
    }, Z)
  }), /* @__PURE__ */ i.createElement("img", p({}, c, {
    className: P("".concat(a, "-img"), q({}, "".concat(a, "-img-placeholder"), l === !0), U),
    style: v({
      height: d
    }, n),
    ref: Ce
  }, ge, {
    width: N,
    height: d,
    onError: X
  })), G === "loading" && /* @__PURE__ */ i.createElement("div", {
    "aria-hidden": "true",
    className: "".concat(a, "-placeholder")
  }, l), O && m && /* @__PURE__ */ i.createElement("div", {
    className: P("".concat(a, "-mask"), te),
    style: {
      display: (n == null ? void 0 : n.display) === "none" ? "none" : void 0
    }
  }, O)), !w && m && /* @__PURE__ */ i.createElement(Oe, p({
    "aria-hidden": !V,
    visible: V,
    prefixCls: Q,
    onClose: he,
    mousePosition: pe,
    src: C,
    alt: K,
    fallback: x,
    getContainer: ie,
    icons: le,
    movable: oe,
    scaleStep: ne,
    minScale: se,
    maxScale: me,
    rootClassName: y,
    imageRender: ce,
    imgCommonProps: c,
    toolbarRender: ve
  }, de)));
};
J.PreviewGroup = $e;
J.displayName = "Image";
export {
  J as default
};
