"use client";
"use client";
import { cn as e } from "../../../lib/utils.js";
import * as t from "react";
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
import * as a from "recharts";
//#region lib/components/ui/atoms/chart.tsx
var o = {
	light: "",
	dark: ".dark"
}, s = {
	width: 320,
	height: 200
}, c = t.createContext(null);
function l() {
	let e = t.useContext(c);
	if (!e) throw Error("useChart must be used within a <ChartContainer />");
	return e;
}
function u({ id: n, className: o, children: l, config: u, initialDimension: f = s, ...p }) {
	let m = t.useId(), h = `chart-${n ?? m.replace(/:/g, "")}`;
	return /* @__PURE__ */ r(c.Provider, {
		value: { config: u },
		children: /* @__PURE__ */ i("div", {
			className: e("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden", o),
			"data-chart": h,
			"data-slot": "chart",
			...p,
			children: [/* @__PURE__ */ r(d, {
				config: u,
				id: h
			}), /* @__PURE__ */ r(a.ResponsiveContainer, {
				initialDimension: f,
				children: l
			})]
		})
	});
}
var d = ({ id: e, config: t }) => {
	let n = Object.entries(t).filter(([, e]) => e.theme ?? e.color);
	return n.length ? /* @__PURE__ */ r("style", { children: Object.entries(o).map(([t, r]) => `
${r} [data-chart=${e}] {
${n.map(([e, n]) => {
		let r = n.theme?.[t] ?? n.color;
		return r ? `  --color-${e}: ${r};` : null;
	}).filter(Boolean).join("\n")}
}`).join("\n") }) : null;
};
function f({ item: t, index: a, config: o, indicator: s, hideIndicator: c, color: l, formatter: u, nameKey: d, nestLabel: f, tooltipLabel: p }) {
	let m = _(o, t, `${d ?? t.name ?? t.dataKey ?? "value"}`), h = l ?? t.payload?.fill ?? t.color, g = `${t.dataKey ?? t.name ?? a}`;
	return /* @__PURE__ */ r("div", {
		className: e("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground", s === "dot" && "items-center"),
		children: u && t?.value !== void 0 && t.name ? u(t.value, t.name, t, a, t.payload) : /* @__PURE__ */ i(n, { children: [m?.icon ? /* @__PURE__ */ r(m.icon, {}) : !c && /* @__PURE__ */ r("div", {
			className: e("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", {
				"h-2.5 w-2.5": s === "dot",
				"w-1": s === "line",
				"w-0 border-[1.5px] border-dashed bg-transparent": s === "dashed",
				"my-0.5": f && s === "dashed"
			}),
			style: {
				"--color-bg": h,
				"--color-border": h
			}
		}), /* @__PURE__ */ i("div", {
			className: e("flex flex-1 justify-between leading-none", f ? "items-end" : "items-center"),
			children: [/* @__PURE__ */ i("div", {
				className: "grid gap-1.5",
				children: [f ? p : null, /* @__PURE__ */ r("span", {
					className: "text-muted-foreground",
					children: m?.label ?? t.name
				})]
			}), t.value != null && /* @__PURE__ */ r("span", {
				className: "font-medium font-mono text-foreground tabular-nums",
				children: typeof t.value == "number" ? t.value.toLocaleString() : String(t.value)
			})]
		})] })
	}, g);
}
var p = a.Tooltip;
function m({ active: n, payload: a, className: o, indicator: s = "dot", hideLabel: c = !1, hideIndicator: u = !1, label: d, labelFormatter: p, labelClassName: m, formatter: h, color: g, nameKey: v, labelKey: y }) {
	let { config: b } = l(), x = t.useMemo(() => {
		if (c || !a?.length) return null;
		let [t] = a, n = _(b, t, `${y ?? t?.dataKey ?? t?.name ?? "value"}`), i = !y && typeof d == "string" ? b[d]?.label ?? d : n?.label;
		return p ? /* @__PURE__ */ r("div", {
			className: e("font-medium", m),
			children: p(i, a)
		}) : i ? /* @__PURE__ */ r("div", {
			className: e("font-medium", m),
			children: i
		}) : null;
	}, [
		d,
		p,
		a,
		c,
		m,
		b,
		y
	]);
	if (!(n && a?.length)) return null;
	let S = a.length === 1 && s !== "dot";
	return /* @__PURE__ */ i("div", {
		className: e("grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl", o),
		children: [S ? null : x, /* @__PURE__ */ r("div", {
			className: "grid gap-1.5",
			children: a.filter((e) => e.type !== "none").map((e, t) => /* @__PURE__ */ r(f, {
				color: g,
				config: b,
				formatter: h,
				hideIndicator: u,
				index: t,
				indicator: s,
				item: e,
				nameKey: v,
				nestLabel: S,
				tooltipLabel: x
			}, `${e.dataKey ?? e.name ?? t}`))
		})]
	});
}
var h = a.Legend;
function g({ className: t, hideIcon: n = !1, payload: a, verticalAlign: o = "bottom", nameKey: s }) {
	let { config: c } = l();
	return a?.length ? /* @__PURE__ */ r("div", {
		className: e("flex items-center justify-center gap-4", o === "top" ? "pb-3" : "pt-3", t),
		children: a.filter((e) => e.type !== "none").map((t, a) => {
			let o = _(c, t, `${s ?? t.dataKey ?? "value"}`);
			return /* @__PURE__ */ i("div", {
				className: e("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),
				children: [o?.icon && !n ? /* @__PURE__ */ r(o.icon, {}) : /* @__PURE__ */ r("div", {
					className: "h-2 w-2 shrink-0 rounded-[2px]",
					style: { backgroundColor: t.color }
				}), o?.label]
			}, `${t.dataKey ?? t.value ?? a}`);
		})
	}) : null;
}
function _(e, t, n) {
	if (typeof t != "object" || !t) return;
	let r = "payload" in t && typeof t.payload == "object" && t.payload !== null ? t.payload : void 0, i = n;
	return n in t && typeof t[n] == "string" ? i = t[n] : r && n in r && typeof r[n] == "string" && (i = r[n]), i in e ? e[i] : e[n];
}
//#endregion
export { u as ChartContainer, h as ChartLegend, g as ChartLegendContent, d as ChartStyle, p as ChartTooltip, m as ChartTooltipContent };
