import Io from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import Po from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import O from "../../@babel/runtime/helpers/esm/extends.mjs";
import eo from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import no from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import yo from "../../classnames/index.mjs";
import Do from "../../rc-dialog/es/DialogWrap.mjs";
import "../../rc-dialog/es/Dialog/Content/Panel.mjs";
import Lo from "../../rc-util/es/Dom/addEventListener.mjs";
import V from "../../rc-util/es/KeyCode.mjs";
import s, { useRef as Mo, useContext as Oo, useState as $o, useEffect as oo } from "react";
import { PreviewGroupContext as Fo } from "./context.mjs";
import Xo from "./hooks/useImageTransform.mjs";
import Yo from "./hooks/useMouseEvent.mjs";
import Zo from "./hooks/useTouchEvent.mjs";
import Ao from "./hooks/useStatus.mjs";
import zo from "./Operations.mjs";
import { BASE_SCALE_RATIO as S } from "./previewConfig.mjs";
var Wo = ["fallback", "src", "imgRef"], Ko = ["prefixCls", "src", "alt", "fallback", "movable", "onClose", "visible", "icons", "rootClassName", "closeIcon", "getContainer", "current", "count", "countRender", "scaleStep", "minScale", "maxScale", "transitionName", "maskTransitionName", "imageRender", "imgCommonProps", "toolbarRender", "onTransform", "onChange"], jo = function(o) {
  var i = o.fallback, b = o.src, w = o.imgRef, x = no(o, Wo), f = Ao({
    src: b,
    fallback: i
  }), m = eo(f, 2), d = m[0], a = m[1];
  return /* @__PURE__ */ s.createElement("img", O({
    ref: function(v) {
      w.current = v, d(v);
    }
  }, x, a));
}, me = function(o) {
  var i = o.prefixCls, b = o.src, w = o.alt, x = o.fallback, f = o.movable, m = f === void 0 ? !0 : f, d = o.onClose, a = o.visible, k = o.icons, v = k === void 0 ? {} : k, $ = o.rootClassName, ao = o.closeIcon, F = o.getContainer, X = o.current, r = X === void 0 ? 0 : X, Y = o.count, g = Y === void 0 ? 1 : Y, ro = o.countRender, Z = o.scaleStep, h = Z === void 0 ? 0.5 : Z, A = o.minScale, _ = A === void 0 ? 1 : A, z = o.maxScale, W = z === void 0 ? 50 : z, K = o.transitionName, io = K === void 0 ? "zoom" : K, j = o.maskTransitionName, G = j === void 0 ? "fade" : j, B = o.imageRender, co = o.imgCommonProps, so = o.toolbarRender, lo = o.onTransform, l = o.onChange, N = no(o, Ko), C = Mo(), E = Oo(Fo), I = E && g > 1, mo = E && g >= 1, uo = $o(!0), H = eo(uo, 2), P = H[0], y = H[1], p = Xo(C, _, W, lo), n = p.transform, D = p.resetTransform, c = p.updateTransform, u = p.dispatchZoomChange, L = Yo(C, m, a, h, n, c, u), fo = L.isMoving, vo = L.onMouseDown, go = L.onWheel, R = Zo(C, m, a, _, n, c, u), ho = R.isTouching, Co = R.onTouchStart, po = R.onTouchMove, q = R.onTouchEnd, M = n.rotate, T = n.scale, Ro = yo(Po({}, "".concat(i, "-moving"), fo));
  oo(function() {
    P || y(!0);
  }, [P]);
  var To = function() {
    D("close");
  }, So = function() {
    u(S + h, "zoomIn");
  }, bo = function() {
    u(S / (S + h), "zoomOut");
  }, wo = function() {
    c({
      rotate: M + 90
    }, "rotateRight");
  }, xo = function() {
    c({
      rotate: M - 90
    }, "rotateLeft");
  }, ko = function() {
    c({
      flipX: !n.flipX
    }, "flipX");
  }, _o = function() {
    c({
      flipY: !n.flipY
    }, "flipY");
  }, J = function(e) {
    e == null || e.preventDefault(), e == null || e.stopPropagation(), r > 0 && (y(!1), D("prev"), l == null || l(r - 1, r));
  }, Q = function(e) {
    e == null || e.preventDefault(), e == null || e.stopPropagation(), r < g - 1 && (y(!1), D("next"), l == null || l(r + 1, r));
  }, No = function(e) {
    !a || !I || (e.keyCode === V.LEFT ? J() : e.keyCode === V.RIGHT && Q());
  }, Eo = function(e) {
    a && (T !== 1 ? c({
      x: 0,
      y: 0,
      scale: 1
    }, "doubleClick") : u(S + h, "doubleClick", e.clientX, e.clientY));
  };
  oo(function() {
    var t = Lo(window, "keydown", No, !1);
    return function() {
      t.remove();
    };
  }, [a, I, r]);
  var U = /* @__PURE__ */ s.createElement(jo, O({}, co, {
    width: o.width,
    height: o.height,
    imgRef: C,
    className: "".concat(i, "-img"),
    alt: w,
    style: {
      transform: "translate3d(".concat(n.x, "px, ").concat(n.y, "px, 0) scale3d(").concat(n.flipX ? "-" : "").concat(T, ", ").concat(n.flipY ? "-" : "").concat(T, ", 1) rotate(").concat(M, "deg)"),
      transitionDuration: (!P || ho) && "0s"
    },
    fallback: x,
    src: b,
    onWheel: go,
    onMouseDown: vo,
    onDoubleClick: Eo,
    onTouchStart: Co,
    onTouchMove: po,
    onTouchEnd: q,
    onTouchCancel: q
  }));
  return /* @__PURE__ */ s.createElement(s.Fragment, null, /* @__PURE__ */ s.createElement(Do, O({
    transitionName: io,
    maskTransitionName: G,
    closable: !1,
    keyboard: !0,
    prefixCls: i,
    onClose: d,
    visible: a,
    classNames: {
      wrapper: Ro
    },
    rootClassName: $,
    getContainer: F
  }, N, {
    afterClose: To
  }), /* @__PURE__ */ s.createElement("div", {
    className: "".concat(i, "-img-wrapper")
  }, B ? B(U, Io({
    transform: n
  }, E ? {
    current: r
  } : {})) : U)), /* @__PURE__ */ s.createElement(zo, {
    visible: a,
    transform: n,
    maskTransitionName: G,
    closeIcon: ao,
    getContainer: F,
    prefixCls: i,
    rootClassName: $,
    icons: v,
    countRender: ro,
    showSwitch: I,
    showProgress: mo,
    current: r,
    count: g,
    scale: T,
    minScale: _,
    maxScale: W,
    toolbarRender: so,
    onSwitchLeft: J,
    onSwitchRight: Q,
    onZoomIn: So,
    onZoomOut: bo,
    onRotateRight: wo,
    onRotateLeft: xo,
    onFlipX: ko,
    onFlipY: _o,
    onClose: d,
    zIndex: N.zIndex !== void 0 ? N.zIndex + 1 : void 0
  }));
};
export {
  me as default
};
