import s from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import G from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import { getClientSize as J } from "../../../rc-util/es/Dom/css.mjs";
import K from "../../../rc-util/es/isEqual.mjs";
import M from "../../../rc-util/es/raf.mjs";
import { useRef as x, useState as N } from "react";
var u = {
  x: 0,
  y: 0,
  rotate: 0,
  scale: 1,
  flipX: !1,
  flipY: !1
};
function tr(H, p, m, i) {
  var v = x(null), d = x([]), I = N(u), g = G(I, 2), r = g[0], T = g[1], L = function(f) {
    T(u), i && !K(u, r) && i({
      transform: u,
      action: f
    });
  }, w = function(f, l) {
    v.current === null && (d.current = [], v.current = M(function() {
      T(function(o) {
        var t = o;
        return d.current.forEach(function(h) {
          t = s(s({}, t), h);
        }), v.current = null, i == null || i({
          transform: t,
          action: l
        }), t;
      });
    })), d.current.push(s(s({}, r), f));
  }, S = function(f, l, o, t, h) {
    var a = H.current, W = a.width, Z = a.height, q = a.offsetWidth, E = a.offsetHeight, O = a.offsetLeft, X = a.offsetTop, c = f, e = r.scale * f;
    e > m ? (e = m, c = m / r.scale) : e < p && (e = h ? e : p, c = e / r.scale);
    var Y = o ?? innerWidth / 2, b = t ?? innerHeight / 2, n = c - 1, j = n * W * 0.5, A = n * Z * 0.5, $ = n * (Y - r.x - O), k = n * (b - r.y - X), C = r.x - ($ - j), R = r.y - (k - A);
    if (f < 1 && e === 1) {
      var z = q * e, B = E * e, _ = J(), D = _.width, F = _.height;
      z <= D && B <= F && (C = 0, R = 0);
    }
    w({
      x: C,
      y: R,
      scale: e
    }, l);
  };
  return {
    transform: r,
    resetTransform: L,
    updateTransform: w,
    dispatchZoomChange: S
  };
}
export {
  tr as default
};
