"use client";
import * as D from "react";
import { clsx as N } from "../../../clsx/dist/clsx.js";
import { filterProps as O } from "../util/ReactUtils.js";
import { polarToCartesian as h, RADIAN as C } from "../util/PolarUtils.js";
import { getPercentValue as j, mathSign as P } from "../util/DataUtils.js";
import { resolveDefaultProps as w } from "../util/resolveDefaultProps.js";
function p() {
  return p = Object.assign ? Object.assign.bind() : function(l) {
    for (var c = 1; c < arguments.length; c++) {
      var n = arguments[c];
      for (var t in n) ({}).hasOwnProperty.call(n, t) && (l[t] = n[t]);
    }
    return l;
  }, p.apply(null, arguments);
}
var V = (l, c) => {
  var n = P(c - l), t = Math.min(Math.abs(c - l), 359.999);
  return n * t;
}, m = (l) => {
  var {
    cx: c,
    cy: n,
    radius: t,
    angle: e,
    sign: a,
    isExternal: y,
    cornerRadius: i,
    cornerIsExternal: s
  } = l, o = i * (y ? 1 : -1) + t, r = Math.asin(i / o) / C, u = s ? e : e + a * r, g = h(c, n, o, u), v = h(c, n, t, u), x = s ? e - a * r : e, d = h(c, n, o * Math.cos(r * C), x);
  return {
    center: g,
    circleTangency: v,
    lineTangency: d,
    theta: r
  };
}, I = (l) => {
  var {
    cx: c,
    cy: n,
    innerRadius: t,
    outerRadius: e,
    startAngle: a,
    endAngle: y
  } = l, i = V(a, y), s = a + i, o = h(c, n, e, a), r = h(c, n, e, s), u = "M ".concat(o.x, ",").concat(o.y, `
    A `).concat(e, ",").concat(e, `,0,
    `).concat(+(Math.abs(i) > 180), ",").concat(+(a > s), `,
    `).concat(r.x, ",").concat(r.y, `
  `);
  if (t > 0) {
    var g = h(c, n, t, a), v = h(c, n, t, s);
    u += "L ".concat(v.x, ",").concat(v.y, `
            A `).concat(t, ",").concat(t, `,0,
            `).concat(+(Math.abs(i) > 180), ",").concat(+(a <= s), `,
            `).concat(g.x, ",").concat(g.y, " Z");
  } else
    u += "L ".concat(c, ",").concat(n, " Z");
  return u;
}, W = (l) => {
  var {
    cx: c,
    cy: n,
    innerRadius: t,
    outerRadius: e,
    cornerRadius: a,
    forceCornerRadius: y,
    cornerIsExternal: i,
    startAngle: s,
    endAngle: o
  } = l, r = P(o - s), {
    circleTangency: u,
    lineTangency: g,
    theta: v
  } = m({
    cx: c,
    cy: n,
    radius: e,
    angle: s,
    sign: r,
    cornerRadius: a,
    cornerIsExternal: i
  }), {
    circleTangency: x,
    lineTangency: d,
    theta: L
  } = m({
    cx: c,
    cy: n,
    radius: e,
    angle: o,
    sign: -r,
    cornerRadius: a,
    cornerIsExternal: i
  }), A = i ? Math.abs(s - o) : Math.abs(s - o) - v - L;
  if (A < 0)
    return y ? "M ".concat(g.x, ",").concat(g.y, `
        a`).concat(a, ",").concat(a, ",0,0,1,").concat(a * 2, `,0
        a`).concat(a, ",").concat(a, ",0,0,1,").concat(-a * 2, `,0
      `) : I({
      cx: c,
      cy: n,
      innerRadius: t,
      outerRadius: e,
      startAngle: s,
      endAngle: o
    });
  var f = "M ".concat(g.x, ",").concat(g.y, `
    A`).concat(a, ",").concat(a, ",0,0,").concat(+(r < 0), ",").concat(u.x, ",").concat(u.y, `
    A`).concat(e, ",").concat(e, ",0,").concat(+(A > 180), ",").concat(+(r < 0), ",").concat(x.x, ",").concat(x.y, `
    A`).concat(a, ",").concat(a, ",0,0,").concat(+(r < 0), ",").concat(d.x, ",").concat(d.y, `
  `);
  if (t > 0) {
    var {
      circleTangency: R,
      lineTangency: M,
      theta: Z
    } = m({
      cx: c,
      cy: n,
      radius: t,
      angle: s,
      sign: r,
      isExternal: !0,
      cornerRadius: a,
      cornerIsExternal: i
    }), {
      circleTangency: T,
      lineTangency: b,
      theta: S
    } = m({
      cx: c,
      cy: n,
      radius: t,
      angle: o,
      sign: -r,
      isExternal: !0,
      cornerRadius: a,
      cornerIsExternal: i
    }), E = i ? Math.abs(s - o) : Math.abs(s - o) - Z - S;
    if (E < 0 && a === 0)
      return "".concat(f, "L").concat(c, ",").concat(n, "Z");
    f += "L".concat(b.x, ",").concat(b.y, `
      A`).concat(a, ",").concat(a, ",0,0,").concat(+(r < 0), ",").concat(T.x, ",").concat(T.y, `
      A`).concat(t, ",").concat(t, ",0,").concat(+(E > 180), ",").concat(+(r > 0), ",").concat(R.x, ",").concat(R.y, `
      A`).concat(a, ",").concat(a, ",0,0,").concat(+(r < 0), ",").concat(M.x, ",").concat(M.y, "Z");
  } else
    f += "L".concat(c, ",").concat(n, "Z");
  return f;
}, _ = {
  cx: 0,
  cy: 0,
  innerRadius: 0,
  outerRadius: 0,
  startAngle: 0,
  endAngle: 0,
  cornerRadius: 0,
  forceCornerRadius: !1,
  cornerIsExternal: !1
}, G = (l) => {
  var c = w(l, _), {
    cx: n,
    cy: t,
    innerRadius: e,
    outerRadius: a,
    cornerRadius: y,
    forceCornerRadius: i,
    cornerIsExternal: s,
    startAngle: o,
    endAngle: r,
    className: u
  } = c;
  if (a < e || o === r)
    return null;
  var g = N("recharts-sector", u), v = a - e, x = j(y, v, 0, !0), d;
  return x > 0 && Math.abs(o - r) < 360 ? d = W({
    cx: n,
    cy: t,
    innerRadius: e,
    outerRadius: a,
    cornerRadius: Math.min(x, v / 2),
    forceCornerRadius: i,
    cornerIsExternal: s,
    startAngle: o,
    endAngle: r
  }) : d = I({
    cx: n,
    cy: t,
    innerRadius: e,
    outerRadius: a,
    startAngle: o,
    endAngle: r
  }), /* @__PURE__ */ D.createElement("path", p({}, O(c, !0), {
    className: g,
    d
  }));
};
export {
  G as Sector
};
