import { jsx as t, jsxs as Y } from "react/jsx-runtime";
import u from "react";
import { Legend as v, ResponsiveContainer as Z, RadialBarChart as ee, RadialBar as te, Cell as oe, PolarAngleAxis as ne, DefaultLegendContent as ie } from "recharts";
import { isObject as D, isFunction as f } from "es-toolkit/compat";
import { getColor as g, getFromDefaultColors as A, CURSOR_BACKGROUND_COLOR as re } from "./chartHelper.js";
import { getLegendDefaultProps as ae } from "./Legend.js";
import le from "./ChartTooltip.js";
import se from "../../hooks/useElementSize.js";
const Ce = (w) => {
  const {
    width: l,
    height: s,
    data: c = [],
    dataKey: i = "value",
    startAngle: L = 180,
    endAngle: S = 0,
    innerRadius: T = "30%",
    outerRadius: W = "100%",
    legend: d = /* @__PURE__ */ t(v, {}),
    textOptions: C,
    radialBarOptions: k,
    containerOptions: r,
    showBarLabel: j = !1,
    cornerRadius: z = 30,
    background: E = !0,
    range: R,
    tooltip: p = !1,
    ...F
  } = w, {
    text: H,
    size: I = "500%",
    weight: N = "normal",
    color: a = "gray-darkest",
    ...$
  } = C || {}, K = {
    fontSize: I,
    fontWeight: N,
    fill: a && g(a)
  }, U = D(p) ? p.props : {}, V = D(d) ? { ...ae(), ...d.props } : {}, { content: n, iconType: y, ..._ } = V, G = c.map((e, o) => {
    const h = f(i) ? i(e) : e[i], X = g(e.color) ?? e.color ?? A(o);
    return {
      value: e.name ?? `${o + 1}`,
      color: X,
      type: y ?? "circle",
      payload: { value: h }
    };
  }), x = u.useRef(null), [P, B] = se(x), O = r?.width, b = r?.height, q = typeof O == "number" && O > 0 || typeof b == "number" && b > 0, J = P && B ? { width: P, height: B } : void 0, m = r?.initialDimension ?? J, M = !!m || q, Q = {
    minHeight: 1,
    minWidth: 1,
    ...r,
    ...m ? { initialDimension: m } : {}
  };
  return /* @__PURE__ */ t("div", { ref: x, style: { width: "100%", height: "100%" }, children: M && /* @__PURE__ */ t(Z, { ...Q, children: /* @__PURE__ */ Y(
    ee,
    {
      width: l,
      height: s,
      data: c,
      innerRadius: T,
      outerRadius: W,
      startAngle: L,
      endAngle: S,
      ...F,
      children: [
        /* @__PURE__ */ t(
          te,
          {
            label: j && { fill: "#666", position: "insideStart" },
            background: E,
            dataKey: i,
            cornerRadius: z,
            ...k,
            children: c.map((e, o) => {
              const h = g(e.color) || A(o);
              return /* @__PURE__ */ t(
                oe,
                {
                  fill: f(a) ? a(e, o) : h
                },
                `cell-${o}`
              );
            })
          }
        ),
        R && /* @__PURE__ */ t(ne, { type: "number", domain: R, angleAxisId: 0, tick: !1 }),
        C && /* @__PURE__ */ t(
          "text",
          {
            x: l ? l / 2 : "50%",
            y: s ? s / 2 : "50%",
            textAnchor: "middle",
            dominantBaseline: "middle",
            className: "radialbarchart-text",
            style: K,
            ...$,
            children: H
          }
        ),
        d && /* @__PURE__ */ t(
          v,
          {
            formatter: (e) => /* @__PURE__ */ t("span", { className: "text-color-darker", children: e }),
            iconType: y,
            content: (e) => {
              const o = { ...e, payload: G };
              return n ? f(n) ? n(o) : u.isValidElement(n) ? u.cloneElement(n, o) : n : /* @__PURE__ */ t(ie, { ...o });
            },
            ..._
          }
        ),
        p && /* @__PURE__ */ t(le, { cursor: { fill: re }, ...U })
      ]
    }
  ) }) });
};
export {
  Ce as default
};
//# sourceMappingURL=RadialBarChart.js.map
