import v, { useRef as h, useEffect as b } from "react";
import x from "./index-cropper.esm.js";
var m = function() {
  return m = Object.assign || function(a) {
    for (var e, r = 1, o = arguments.length; r < o; r++) {
      e = arguments[r];
      for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && (a[n] = e[n]);
    }
    return a;
  }, m.apply(this, arguments);
};
function z(t, a) {
  var e = {};
  for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && a.indexOf(r) < 0 && (e[r] = t[r]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var o = 0, r = Object.getOwnPropertySymbols(t); o < r.length; o++)
      a.indexOf(r[o]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[o]) && (e[r[o]] = t[r[o]]);
  return e;
}
var C = function(t, a) {
  a === void 0 && (a = {});
  var e = a.enable, r = e === void 0 ? !0 : e, o = a.scaleX, n = o === void 0 ? 1 : o, u = a.scaleY, p = u === void 0 ? 1 : u, s = a.zoomTo, f = s === void 0 ? 0 : s, d = a.rotateTo;
  r ? t.enable() : t.disable(), t.scaleX(n), t.scaleY(p), d !== void 0 && t.rotateTo(d), f > 0 && t.zoomTo(f);
}, I = function() {
  for (var t = [], a = 0; a < arguments.length; a++)
    t[a] = arguments[a];
  var e = h(null);
  return v.useEffect(function() {
    t.forEach(function(r) {
      r && (typeof r == "function" ? r(e.current) : r.current = e.current);
    });
  }, [t]), e;
}, P = v.forwardRef(function(t, a) {
  var e = z(t, []), r = e.dragMode, o = r === void 0 ? "crop" : r, n = e.src, u = e.style, p = e.className, s = e.crossOrigin, f = e.scaleX, d = e.scaleY, R = e.enable, y = e.zoomTo, X = e.rotateTo, O = e.alt, Y = O === void 0 ? "picture" : O, T = e.ready, _ = e.onInitialized, j = z(e, ["dragMode", "src", "style", "className", "crossOrigin", "scaleX", "scaleY", "enable", "zoomTo", "rotateTo", "alt", "ready", "onInitialized"]), w = { scaleY: d, scaleX: f, enable: R, zoomTo: y, rotateTo: X }, E = h(null), l = I(a, E);
  return b(function() {
    var c;
    !((c = l.current) === null || c === void 0) && c.cropper && typeof y == "number" && l.current.cropper.zoomTo(y);
  }, [e.zoomTo]), b(function() {
    var c;
    !((c = l.current) === null || c === void 0) && c.cropper && typeof n < "u" && l.current.cropper.reset().clear().replace(n);
  }, [n]), b(function() {
    if (l.current !== null) {
      var c = new x(l.current, m(m({ dragMode: o }, j), { ready: function(i) {
        i.currentTarget !== null && C(i.currentTarget.cropper, w), T && T(i);
      } }));
      _ && _(c);
    }
    return function() {
      var i, g;
      (g = (i = l.current) === null || i === void 0 ? void 0 : i.cropper) === null || g === void 0 || g.destroy();
    };
  }, [l]), v.createElement(
    "div",
    { style: u, className: p },
    v.createElement("img", { crossOrigin: s, src: n, alt: Y, style: { opacity: 0, maxWidth: "100%" }, ref: l })
  );
});
export {
  P as Cropper,
  P as default
};
