"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { createContext, useContext } from "react";
const ChartContext = createContext(null);
function useChart() {
  const context = useContext(ChartContext);
  if (!context) {
    throw new Error("useChart must be used within a ChartContainer");
  }
  return context;
}
function ChartContainer({
  config,
  children,
  className,
  ...props
}) {
  const configId = React.useId();
  return /* @__PURE__ */ jsx(ChartContext.Provider, { value: { config }, children: /* @__PURE__ */ jsx(
    "div",
    {
      "data-chart": configId,
      className,
      ...props,
      style: {
        ...props.style,
        "--color-chart-1": "var(--chart-1)",
        "--color-chart-2": "var(--chart-2)",
        "--color-chart-3": "var(--chart-3)",
        "--color-chart-4": "var(--chart-4)",
        "--color-chart-5": "var(--chart-5)",
        ...Object.entries(config).reduce(
          (acc, [key, value]) => {
            if (value.color) {
              acc[`--color-${key}`] = value.color;
            }
            return acc;
          },
          {}
        )
      },
      children
    }
  ) });
}
function ChartTooltipContent({
  active,
  payload,
  label,
  labelFormatter,
  valueFormatter = (value) => value.toLocaleString(),
  hideLabel = false,
  indicator = "dot",
  nameKey,
  categoryLabels
}) {
  if (!active || !payload?.length) {
    return null;
  }
  return /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-popover px-3 py-2 text-popover-foreground shadow-md", children: [
    !hideLabel && label && /* @__PURE__ */ jsx("div", { className: "mb-1 text-sm font-medium", children: labelFormatter ? labelFormatter(label, payload) : label }),
    /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: payload.map((item, index) => {
      const rawName = nameKey && item.payload ? String(item.payload[nameKey]) : item.name;
      const name = categoryLabels?.[rawName] ?? rawName;
      return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-8", children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
          indicator === "dot" && /* @__PURE__ */ jsx(
            "span",
            {
              className: "h-2.5 w-2.5 shrink-0 rounded-full",
              style: { backgroundColor: item.color }
            }
          ),
          indicator === "line" && /* @__PURE__ */ jsx(
            "span",
            {
              className: "h-0.5 w-3 shrink-0 rounded-full",
              style: { backgroundColor: item.color }
            }
          ),
          indicator === "dashed" && /* @__PURE__ */ jsx(
            "span",
            {
              className: "h-0.5 w-3 shrink-0 rounded-full border-t-2 border-dashed",
              style: { borderColor: item.color }
            }
          ),
          /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: name })
        ] }),
        /* @__PURE__ */ jsx("span", { className: "text-sm font-medium tabular-nums", children: valueFormatter(item.value) })
      ] }, index);
    }) })
  ] });
}
const CHART_COLORS = [
  "var(--chart-1)",
  "var(--chart-2)",
  "var(--chart-3)",
  "var(--chart-4)",
  "var(--chart-5)"
];
const NAMED_COLORS = {
  blue: "var(--chart-blue)",
  emerald: "var(--chart-emerald)",
  amber: "var(--chart-amber)",
  rose: "var(--chart-rose)",
  violet: "var(--chart-violet)",
  cyan: "var(--chart-cyan)",
  indigo: "var(--chart-indigo)",
  pink: "var(--chart-pink)",
  teal: "var(--chart-teal)",
  orange: "var(--chart-orange)"
};
function getChartColor(index) {
  return CHART_COLORS[index % CHART_COLORS.length];
}
function resolveChartColor(color, index) {
  if (color && NAMED_COLORS[color]) {
    return NAMED_COLORS[color];
  }
  return CHART_COLORS[index % CHART_COLORS.length];
}
export {
  CHART_COLORS,
  ChartContainer,
  ChartTooltipContent,
  NAMED_COLORS,
  getChartColor,
  resolveChartColor,
  useChart
};
//# sourceMappingURL=ChartUtils.js.map
