import { jsx as t, jsxs as b } from "react/jsx-runtime";
import { useMemo as R } from "react";
import { PieChart as A, Pie as _, LabelList as M, Label as W } from "recharts";
import { ChartContainer as Y, ChartTooltip as D, ChartTooltipContent as E, ChartLegend as F, ChartLegendContent as G } from "../ChartPrimitive.js";
import H from "../../utils/getCenterSubY.js";
const J = ({
  id: x,
  chartConfig: g,
  dataItems: p,
  showLegend: C = !1,
  height: N = 300,
  size: n,
  tooltipContent: L,
  showLabel: S,
  hideLegendIcon: K = !1
}) => {
  const v = R(
    () => ({ cx: r, cy: f, x: l, y: s, textAnchor: h, dominantBaseline: d, value: i }) => {
      const o = {
        cx: Number(r),
        cy: Number(f),
        x: Number(l),
        y: Number(s)
      };
      return /* @__PURE__ */ t("text", { ...o, textAnchor: String(h), dominantBaseline: String(d), fill: "var(--base-foreground)", children: String(i) });
    },
    []
  ), a = n === "100%" || n === "auto", m = typeof n == "number" ? n : N, k = a ? "size-full aspect-square [container-type:size] [&_.recharts-text]:fill-background" : "mx-auto aspect-square [&_.recharts-text]:fill-background", z = a ? "fill-[var(--base-foreground)] text-[length:clamp(1.125rem,9cqmin,2.5rem)] font-[var(--font-weight-bold)]" : "fill-[var(--base-foreground)] text-[length:var(--typography-base-sizes-3x-large-font-size)] font-[var(--font-weight-bold)]", P = a ? "fill-[var(--base-muted-foreground)] text-[length:clamp(0.625rem,3.5cqmin,0.875rem)] font-[var(--font-weight-normal)]" : "fill-[var(--base-muted-foreground)] text-[length:var(--typography-base-sizes-extra-small-font-size)] font-[var(--font-weight-normal)] leading-[var(--typography-base-sizes-extra-small-line-height)]";
  return /* @__PURE__ */ t(
    Y,
    {
      id: x,
      config: g,
      className: k,
      ...!a && {
        style: { height: m }
      },
      children: /* @__PURE__ */ b(
        A,
        {
          accessibilityLayer: !0,
          ...!a && { width: m, height: m },
          margin: {
            left: 12,
            right: 12
          },
          children: [
            /* @__PURE__ */ t(D, { cursor: !1, content: /* @__PURE__ */ t(E, { hideLabel: !0, ...L }) }),
            p.map((r) => {
              const {
                data: f,
                dataKey: l,
                nameKey: s,
                separator: h = !0,
                labelLine: d = !0,
                pieLabel: i,
                customPieLabel: o,
                innerRadius: $,
                outerRadius: q,
                strokeWidth: T,
                activeShape: j,
                centerTitle: c,
                centerSub: u
              } = r;
              return /* @__PURE__ */ b(
                _,
                {
                  data: f,
                  dataKey: l,
                  nameKey: s,
                  labelLine: d,
                  label: S ? v : !1,
                  innerRadius: $,
                  outerRadius: q,
                  strokeWidth: T,
                  activeShape: j,
                  ...!h && { stroke: "0" },
                  ...i && { label: i },
                  children: [
                    o && /* @__PURE__ */ t(
                      M,
                      {
                        dataKey: o.dataKey,
                        className: "fill-[var(--base-background)]",
                        stroke: "none",
                        fontSize: 12,
                        formatter: (e) => {
                          var y;
                          return (y = g[String(e)]) == null ? void 0 : y.label;
                        }
                      }
                    ),
                    (c || u) && /* @__PURE__ */ t(
                      W,
                      {
                        content: ({ viewBox: e }) => {
                          if (e && "cx" in e && "cy" in e)
                            return /* @__PURE__ */ b("text", { x: e.cx, y: e.cy, textAnchor: "middle", dominantBaseline: "middle", children: [
                              c && /* @__PURE__ */ t("tspan", { x: e.cx, ...!a && { y: e.cy }, className: z, children: c }),
                              u && /* @__PURE__ */ t(
                                "tspan",
                                {
                                  x: e.cx,
                                  ...a ? c ? { dy: "2.2em" } : {} : { y: H(e.cy) },
                                  className: P,
                                  children: u
                                }
                              )
                            ] });
                        }
                      }
                    )
                  ]
                },
                `${l}-${s}`
              );
            }),
            C && p.map((r) => /* @__PURE__ */ t(
              F,
              {
                content: /* @__PURE__ */ t(G, { nameKey: r.nameKey, hideIcon: K }),
                className: "-translate-y-2 flex-wrap gap-2 [&>*]:basis-1/4 [&>*]:justify-center"
              },
              `${r.dataKey}-${r.nameKey}`
            ))
          ]
        }
      )
    }
  );
};
J.displayName = "PieChart";
export {
  J as default
};
//# sourceMappingURL=PieChart.js.map
