"use client";
import * as P from "react";
import { useRef as u, useState as z, useEffect as F, useMemo as G } from "react";
import { clsx as Q } from "../../../clsx/dist/clsx.js";
import { filterProps as B } from "../util/ReactUtils.js";
import { resolveDefaultProps as $ } from "../util/resolveDefaultProps.js";
import { JavascriptAnimate as x } from "../animation/JavascriptAnimate.js";
import { interpolate as y } from "../util/DataUtils.js";
import { useAnimationId as _ } from "../util/useAnimationId.js";
import { getTransitionVal as d } from "../animation/util.js";
function H(r, t) {
  var c = Object.keys(r);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(r);
    t && (n = n.filter(function(p) {
      return Object.getOwnPropertyDescriptor(r, p).enumerable;
    })), c.push.apply(c, n);
  }
  return c;
}
function X(r) {
  for (var t = 1; t < arguments.length; t++) {
    var c = arguments[t] != null ? arguments[t] : {};
    t % 2 ? H(Object(c), !0).forEach(function(n) {
      R(r, n, c[n]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(c)) : H(Object(c)).forEach(function(n) {
      Object.defineProperty(r, n, Object.getOwnPropertyDescriptor(c, n));
    });
  }
  return r;
}
function R(r, t, c) {
  return (t = w(t)) in r ? Object.defineProperty(r, t, { value: c, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = c, r;
}
function w(r) {
  var t = tt(r, "string");
  return typeof t == "symbol" ? t : t + "";
}
function tt(r, t) {
  if (typeof r != "object" || !r) return r;
  var c = r[Symbol.toPrimitive];
  if (c !== void 0) {
    var n = c.call(r, t);
    if (typeof n != "object") return n;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (t === "string" ? String : Number)(r);
}
function O() {
  return O = Object.assign ? Object.assign.bind() : function(r) {
    for (var t = 1; t < arguments.length; t++) {
      var c = arguments[t];
      for (var n in c) ({}).hasOwnProperty.call(c, n) && (r[n] = c[n]);
    }
    return r;
  }, O.apply(null, arguments);
}
var Y = (r, t, c, n, p) => {
  var m = Math.min(Math.abs(c) / 2, Math.abs(n) / 2), v = n >= 0 ? 1 : -1, o = c >= 0 ? 1 : -1, i = n >= 0 && c >= 0 || n < 0 && c < 0 ? 1 : 0, f;
  if (m > 0 && p instanceof Array) {
    for (var a = [0, 0, 0, 0], l = 0, g = 4; l < g; l++)
      a[l] = p[l] > m ? m : p[l];
    f = "M".concat(r, ",").concat(t + v * a[0]), a[0] > 0 && (f += "A ".concat(a[0], ",").concat(a[0], ",0,0,").concat(i, ",").concat(r + o * a[0], ",").concat(t)), f += "L ".concat(r + c - o * a[1], ",").concat(t), a[1] > 0 && (f += "A ".concat(a[1], ",").concat(a[1], ",0,0,").concat(i, `,
        `).concat(r + c, ",").concat(t + v * a[1])), f += "L ".concat(r + c, ",").concat(t + n - v * a[2]), a[2] > 0 && (f += "A ".concat(a[2], ",").concat(a[2], ",0,0,").concat(i, `,
        `).concat(r + c - o * a[2], ",").concat(t + n)), f += "L ".concat(r + o * a[3], ",").concat(t + n), a[3] > 0 && (f += "A ".concat(a[3], ",").concat(a[3], ",0,0,").concat(i, `,
        `).concat(r, ",").concat(t + n - v * a[3])), f += "Z";
  } else if (m > 0 && p === +p && p > 0) {
    var e = Math.min(m, p);
    f = "M ".concat(r, ",").concat(t + v * e, `
            A `).concat(e, ",").concat(e, ",0,0,").concat(i, ",").concat(r + o * e, ",").concat(t, `
            L `).concat(r + c - o * e, ",").concat(t, `
            A `).concat(e, ",").concat(e, ",0,0,").concat(i, ",").concat(r + c, ",").concat(t + v * e, `
            L `).concat(r + c, ",").concat(t + n - v * e, `
            A `).concat(e, ",").concat(e, ",0,0,").concat(i, ",").concat(r + c - o * e, ",").concat(t + n, `
            L `).concat(r + o * e, ",").concat(t + n, `
            A `).concat(e, ",").concat(e, ",0,0,").concat(i, ",").concat(r, ",").concat(t + n - v * e, " Z");
  } else
    f = "M ".concat(r, ",").concat(t, " h ").concat(c, " v ").concat(n, " h ").concat(-c, " Z");
  return f;
}, rt = {
  x: 0,
  y: 0,
  width: 0,
  height: 0,
  // The radius of border
  // The radius of four corners when radius is a number
  // The radius of left-top, right-top, right-bottom, left-bottom when radius is an array
  radius: 0,
  isAnimationActive: !1,
  isUpdateAnimationActive: !1,
  animationBegin: 0,
  animationDuration: 1500,
  animationEasing: "ease"
}, mt = (r) => {
  var t = $(r, rt), c = u(null), [n, p] = z(-1);
  F(() => {
    if (c.current && c.current.getTotalLength)
      try {
        var s = c.current.getTotalLength();
        s && p(s);
      } catch {
      }
  }, []);
  var {
    x: m,
    y: v,
    width: o,
    height: i,
    radius: f,
    className: a
  } = t, {
    animationEasing: l,
    animationDuration: g,
    animationBegin: e,
    isAnimationActive: Z,
    isUpdateAnimationActive: j
  } = t, D = u(o), E = u(i), L = u(m), S = u(v), K = G(() => ({
    x: m,
    y: v,
    width: o,
    height: i,
    radius: f
  }), [m, v, o, i, f]), M = _(K, "rectangle-");
  if (m !== +m || v !== +v || o !== +o || i !== +i || o === 0 || i === 0)
    return null;
  var k = Q("recharts-rectangle", a);
  if (!j)
    return /* @__PURE__ */ P.createElement("path", O({}, B(t, !0), {
      className: k,
      d: Y(m, v, o, i, f)
    }));
  var U = D.current, h = E.current, C = L.current, J = S.current, V = "0px ".concat(n === -1 ? 1 : n, "px"), I = "".concat(n, "px 0px"), q = d(["strokeDasharray"], g, typeof l == "string" ? l : void 0);
  return /* @__PURE__ */ P.createElement(x, {
    animationId: M,
    key: M,
    canBegin: n > 0,
    duration: g,
    easing: l,
    isActive: j,
    begin: e
  }, (s) => {
    var A = y(U, o, s), N = y(h, i, s), T = y(C, m, s), W = y(J, v, s);
    c.current && (D.current = A, E.current = N, L.current = T, S.current = W);
    var b;
    return Z ? s > 0 ? b = {
      transition: q,
      strokeDasharray: I
    } : b = {
      strokeDasharray: V
    } : b = {
      strokeDasharray: I
    }, /* @__PURE__ */ P.createElement("path", O({}, B(t, !0), {
      className: k,
      d: Y(T, W, A, N, f),
      ref: c,
      style: X(X({}, b), t.style)
    }));
  });
};
export {
  mt as Rectangle
};
