import { jsxs as k, jsx as e, Fragment as Be } from "react/jsx-runtime";
import { useRef as be, useState as ie, useMemo as me, useCallback as te, forwardRef as ve, useEffect as $e, useImperativeHandle as Ie } from "react";
import { k as Le, n as We, u as ke } from "./core-CfXsl755.js";
import { N as Pe } from "./index-x8mRM4Jc.js";
const Ne = ["#3b82f6", "#ef4444", "#22c55e", "#f59e0b", "#8b5cf6", "#ec4899", "#06b6d4", "#84cc16"], De = ({
  series: t,
  categories: a,
  width: d = 600,
  height: c = 400,
  title: r,
  showLegend: u = !0,
  showGrid: i = !0,
  yAxisLabel: m,
  xAxisLabel: C,
  stacked: l,
  zoomable: v,
  crosshair: f,
  annotations: S,
  legendInteractive: y,
  onDataPointClick: p,
  exportable: o,
  className: s,
  style: h
}) => {
  const w = be(null), [b, A] = ie(/* @__PURE__ */ new Set()), [N, I] = ie(null), [g, T] = ie(null), [x, O] = ie(!1), B = be(null), R = me(
    () => t.filter(($) => !b.has($.name)),
    [t, b]
  ), G = te(($) => {
    y && A((E) => {
      const Y = new Set(E);
      return Y.has($) ? Y.delete($) : Y.add($), Y;
    });
  }, [y]), j = { top: r ? 40 : 20, right: 20, bottom: C ? 60 : 40, left: m ? 60 : 50 }, W = d - j.left - j.right, U = c - j.top - j.bottom, Z = R[0]?.data.length ?? t[0]?.data.length ?? 0, X = g?.start ?? 0, K = g?.end ?? Z, ee = K - X, he = me(
    () => R.map(($) => ({ ...$, data: $.data.slice(X, K) })),
    [R, X, K]
  ), ne = me(
    () => a?.slice(X, K),
    [a, X, K]
  ), { minY: D, maxY: P, yTicks: re } = me(() => {
    let $;
    if (l) {
      $ = [];
      for (let _ = 0; _ < ee; _++)
        $.push(he.reduce((V, ae) => V + (ae.data[_] || 0), 0));
    } else
      $ = he.flatMap((_) => _.data);
    $.length === 0 && ($ = [0]);
    const E = Math.min(0, ...$), Y = Math.max(0, ...$), ce = Y - E || 1, oe = Math.pow(10, Math.floor(Math.log10(ce))) || 1, n = Math.floor(E / oe) * oe, M = Math.ceil(Y / oe) * oe, z = [];
    for (let _ = n; _ <= M; _ += oe) z.push(Math.round(_ * 1e6) / 1e6);
    return z.length < 2 && z.push(M), { minY: n, maxY: M, yTicks: z };
  }, [he, ee, l]), F = ($) => U - ($ - D) / (P - D || 1) * U, q = ($) => ($ + 0.5) / ee * W, de = ee > 0 ? W / ee / (l ? 1.5 : Math.max(R.length, 1) * 1.5) : 20, xe = te(($) => {
    if (!v) return;
    $.preventDefault();
    const E = g ?? { start: 0, end: Z }, Y = E.end - E.start, ce = (E.start + E.end) / 2, oe = $.deltaY > 0 ? 1.2 : 0.8, n = Math.max(2, Math.min(Z, Math.round(Y * oe))), M = Math.max(0, Math.round(ce - n / 2)), z = Math.min(Z, M + n);
    T({ start: M, end: z });
  }, [v, g, Z]), ye = te(($) => {
    v && (O(!0), B.current = { x: $.clientX, range: g ?? { start: 0, end: Z } });
  }, [v, g, Z]), L = te(($) => {
    const E = w.current?.getBoundingClientRect();
    if (E && I({ x: $.clientX - E.left - j.left, y: $.clientY - E.top - j.top }), x && B.current && v) {
      const Y = $.clientX - B.current.x, ce = W / ee, oe = -Math.round(Y / ce), n = B.current.range, M = n.end - n.start;
      let z = n.start + oe;
      z < 0 && (z = 0), z + M > Z && (z = Z - M), T({ start: z, end: z + M });
    }
  }, [x, v, W, ee, Z, j.left, j.top]), H = te(() => {
    O(!1), B.current = null;
  }, []), J = te(() => {
    I(null), O(!1), B.current = null;
  }, []), pe = te(() => {
    const $ = w.current;
    if (!$) return;
    const E = new XMLSerializer().serializeToString($), Y = document.createElement("canvas");
    Y.width = d, Y.height = c + (u ? 30 : 0);
    const ce = Y.getContext("2d");
    if (!ce) return;
    const oe = new Image();
    oe.onload = () => {
      ce.fillStyle = "#fff", ce.fillRect(0, 0, Y.width, Y.height), ce.drawImage(oe, 0, 0);
      const n = document.createElement("a");
      n.download = "chart.png", n.href = Y.toDataURL("image/png"), n.click();
    }, oe.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(E);
  }, [d, c, u]);
  return /* @__PURE__ */ k("div", { className: `nice-chart ${s || ""}`, style: h, children: [
    o && /* @__PURE__ */ e("button", { type: "button", className: "nice-chart__export-btn", onClick: pe, title: "Export PNG", children: "📷" }),
    /* @__PURE__ */ k(
      "svg",
      {
        ref: w,
        width: d,
        height: c + (u ? 30 : 0),
        className: "nice-chart__svg",
        onWheel: xe,
        onMouseDown: ye,
        onMouseMove: L,
        onMouseUp: H,
        onMouseLeave: J,
        children: [
          /* @__PURE__ */ k("g", { transform: `translate(${j.left},${j.top})`, children: [
            r && /* @__PURE__ */ e("text", { x: W / 2, y: -10, textAnchor: "middle", className: "nice-chart__title", children: r }),
            i && re.map(($) => /* @__PURE__ */ k("g", { children: [
              /* @__PURE__ */ e("line", { x1: 0, y1: F($), x2: W, y2: F($), className: "nice-chart__grid-line" }),
              /* @__PURE__ */ e("text", { x: -8, y: F($) + 4, textAnchor: "end", className: "nice-chart__axis-label", children: $ })
            ] }, $)),
            ne && ne.map(($, E) => /* @__PURE__ */ e("text", { x: q(E), y: U + 20, textAnchor: "middle", className: "nice-chart__axis-label", children: $ }, E)),
            m && /* @__PURE__ */ e("text", { x: -j.left + 14, y: U / 2, textAnchor: "middle", transform: `rotate(-90, -${j.left - 14}, ${U / 2})`, className: "nice-chart__axis-title", children: m }),
            C && /* @__PURE__ */ e("text", { x: W / 2, y: U + 45, textAnchor: "middle", className: "nice-chart__axis-title", children: C }),
            /* @__PURE__ */ e("line", { x1: 0, y1: 0, x2: 0, y2: U, className: "nice-chart__axis" }),
            /* @__PURE__ */ e("line", { x1: 0, y1: U, x2: W, y2: U, className: "nice-chart__axis" }),
            S?.map(($, E) => {
              if ($.type === "line") {
                const Y = F($.value);
                return /* @__PURE__ */ k("g", { children: [
                  /* @__PURE__ */ e("line", { x1: 0, y1: Y, x2: W, y2: Y, stroke: $.color || "#ef4444", strokeWidth: 1.5, strokeDasharray: $.dash || "6,3" }),
                  $.label && /* @__PURE__ */ e("text", { x: W + 4, y: Y + 4, className: "nice-chart__annotation-label", fill: $.color || "#ef4444", children: $.label })
                ] }, E);
              }
              return /* @__PURE__ */ e("text", { x: q($.value), y: -4, textAnchor: "middle", className: "nice-chart__annotation-label", fill: $.color || "#6b7280", children: $.label }, E);
            }),
            f && N && N.x >= 0 && N.x <= W && N.y >= 0 && N.y <= U && /* @__PURE__ */ k(Be, { children: [
              /* @__PURE__ */ e("line", { x1: N.x, y1: 0, x2: N.x, y2: U, stroke: "#9ca3af", strokeWidth: 1, strokeDasharray: "4,2" }),
              /* @__PURE__ */ e("line", { x1: 0, y1: N.y, x2: W, y2: N.y, stroke: "#9ca3af", strokeWidth: 1, strokeDasharray: "4,2" })
            ] }),
            he.map(($, E) => {
              const Y = $.color || Ne[E % Ne.length], ce = $.type || "bar";
              if (ce === "bar")
                return /* @__PURE__ */ e("g", { children: $.data.map((n, M) => {
                  let z, _;
                  if (l) {
                    const ae = he.slice(0, E).reduce((ue, se) => ue + (se.data[M] || 0), 0);
                    z = F(ae + n), _ = F(ae) - z;
                  } else
                    z = F(Math.max(0, n)), _ = Math.abs(F(n) - F(0));
                  const V = l ? q(M) - de / 2 : q(M) - he.length * de / 2 + E * de;
                  return /* @__PURE__ */ e(
                    "rect",
                    {
                      x: V,
                      y: z,
                      width: de * 0.9,
                      height: Math.max(0, _),
                      fill: Y,
                      rx: 2,
                      style: p ? { cursor: "pointer" } : void 0,
                      onClick: p ? () => p($.name, X + M, n) : void 0,
                      children: /* @__PURE__ */ e("title", { children: `${$.name}: ${n}` })
                    },
                    M
                  );
                }) }, $.name);
              const oe = $.data.map((n, M) => `${q(M)},${F(n)}`);
              return /* @__PURE__ */ k("g", { children: [
                ce === "area" && /* @__PURE__ */ e(
                  "polygon",
                  {
                    points: `${q(0)},${F(0)} ${oe.join(" ")} ${q(ee - 1)},${F(0)}`,
                    fill: Y,
                    opacity: 0.15
                  }
                ),
                /* @__PURE__ */ e("polyline", { points: oe.join(" "), fill: "none", stroke: Y, strokeWidth: 2 }),
                $.data.map((n, M) => /* @__PURE__ */ e(
                  "circle",
                  {
                    cx: q(M),
                    cy: F(n),
                    r: 3,
                    fill: Y,
                    style: p ? { cursor: "pointer" } : void 0,
                    onClick: p ? () => p($.name, X + M, n) : void 0,
                    children: /* @__PURE__ */ e("title", { children: `${$.name}: ${n}` })
                  },
                  M
                ))
              ] }, $.name);
            })
          ] }),
          u && /* @__PURE__ */ e("g", { transform: `translate(${j.left}, ${c})`, children: t.map(($, E) => {
            const Y = E * 120, ce = b.has($.name);
            return /* @__PURE__ */ k(
              "g",
              {
                transform: `translate(${Y}, 10)`,
                style: y ? { cursor: "pointer" } : void 0,
                onClick: () => G($.name),
                opacity: ce ? 0.35 : 1,
                children: [
                  /* @__PURE__ */ e("rect", { width: 12, height: 12, rx: 2, fill: $.color || Ne[E % Ne.length] }),
                  /* @__PURE__ */ e(
                    "text",
                    {
                      x: 16,
                      y: 10,
                      className: "nice-chart__legend-text",
                      style: ce ? { textDecoration: "line-through" } : void 0,
                      children: $.name
                    }
                  )
                ]
              },
              $.name
            );
          }) })
        ]
      }
    )
  ] });
}, rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceChart: De
}, Symbol.toStringTag, { value: "Module" }));
function Re(t) {
  if (!t.length)
    return { categories: [], numericFields: [], sampleValues: {} };
  const a = t[0], d = [], c = {};
  let r = null;
  for (const [i, m] of Object.entries(a))
    typeof m == "number" ? (d.push(i), c[i] = t.map((C) => Number(C[i]) || 0)) : !r && (typeof m == "string" || m instanceof Date) && (r = i);
  return { categories: r ? t.map((i) => String(i[r] || "")) : t.map((i, m) => `Item ${m + 1}`), numericFields: d, sampleValues: c };
}
function je(t, a) {
  const { categories: d, numericFields: c, sampleValues: r } = Re(t);
  return { series: c.map((i, m) => ({
    name: i.replace(/([A-Z])/g, " $1").replace(/^./, (C) => C.toUpperCase()).trim(),
    data: r[i],
    type: a === "area" ? "area" : a === "line" ? "line" : "bar"
  })), categories: d };
}
const ct = ve(function(a, d) {
  const {
    rawData: c,
    enableAI: r = !0,
    aiModel: u,
    enableAutoType: i = !0,
    enableInsights: m = !0,
    dataDescription: C,
    onChartSuggestion: l,
    onInsights: v,
    showAIToolbar: f = !0,
    showInsightsOnLoad: S = !1,
    series: y,
    categories: p,
    ...o
  } = a, [s, h] = ie("bar"), [w, b] = ie(null), [A, N] = ie([]), [I, g] = ie(S), [T, x] = ie(null), { t: O } = Pe(), B = Le(), { suggestChartType: R, generateInsights: G, isLoading: j } = We(), W = r && B.isConfigured, { series: U, categories: Z } = c ? je(c, T || s) : { series: y || [], categories: p }, X = te(async () => {
    if (!W || !i)
      return { type: "bar", reason: "Default", config: {} };
    const D = c || (y?.length ? y.flatMap((P) => P.data.map((re, F) => ({ [P.name]: re, index: F }))) : []);
    try {
      const P = await R(D, C), re = {
        type: P.type,
        reason: P.reason,
        config: P.config
      };
      return b(re), h(re.type), l?.(re), re;
    } catch {
      return { type: "bar", reason: "Default fallback", config: {} };
    }
  }, [W, i, c, y, C, R, l]), K = te(async () => {
    if (!W || !m) return [];
    const D = c || (y?.length ? y.flatMap((P) => P.data.map((re, F) => ({ [P.name]: re, category: p?.[F] || F }))) : []);
    try {
      const P = await G(D, T || s);
      return N(P), v?.(P), P;
    } catch {
      return [];
    }
  }, [W, m, c, y, p, s, T, G, v]), ee = te(() => T || s, [T, s]);
  $e(() => {
    W && i && (c?.length || y?.length) && X();
  }, [W, i, c, y]), Ie(d, () => ({
    getSuggestion: X,
    generateInsights: K,
    getCurrentType: ee
  }));
  const he = [
    { type: "bar", icon: "📊", label: "Bar" },
    { type: "line", icon: "📈", label: "Line" },
    { type: "area", icon: "🏔️", label: "Area" },
    { type: "pie", icon: "🥧", label: "Pie" },
    { type: "donut", icon: "🍩", label: "Donut" },
    { type: "scatter", icon: "⭐", label: "Scatter" }
  ], ne = T || s;
  return /* @__PURE__ */ k("div", { className: "nice-chart-ai", "data-testid": a["data-testid"], children: [
    f && W && /* @__PURE__ */ k("div", { className: "nice-chart-ai__toolbar", children: [
      /* @__PURE__ */ k("div", { className: "nice-chart-ai__toolbar-left", children: [
        /* @__PURE__ */ e("span", { className: "nice-chart-ai__badge", children: "AI" }),
        w && /* @__PURE__ */ k("div", { className: "nice-chart-ai__suggestion", children: [
          /* @__PURE__ */ e("span", { className: "nice-chart-ai__suggestion-icon", children: "💡" }),
          /* @__PURE__ */ k("span", { className: "nice-chart-ai__suggestion-text", children: [
            O("chartAI.suggestedType", "Suggested:"),
            " ",
            w.type
          ] }),
          /* @__PURE__ */ k("span", { className: "nice-chart-ai__suggestion-reason", title: w.reason, children: [
            "(",
            w.reason,
            ")"
          ] })
        ] }),
        j && /* @__PURE__ */ e("span", { className: "nice-chart-ai__loading", children: O("chartAI.analyzing", "Analyzing...") })
      ] }),
      /* @__PURE__ */ e("div", { className: "nice-chart-ai__toolbar-center", children: /* @__PURE__ */ e("div", { className: "nice-chart-ai__type-selector", children: he.filter((D) => ["bar", "line", "area"].includes(D.type)).map(({ type: D, icon: P, label: re }) => /* @__PURE__ */ e(
        "button",
        {
          type: "button",
          className: `nice-chart-ai__type-btn ${ne === D ? "nice-chart-ai__type-btn--active" : ""}`,
          onClick: () => x(D),
          title: re,
          children: P
        },
        D
      )) }) }),
      /* @__PURE__ */ k("div", { className: "nice-chart-ai__toolbar-right", children: [
        /* @__PURE__ */ k(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__auto-btn",
            onClick: () => X(),
            disabled: j,
            title: O("chartAI.autoDetect", "Auto-detect best chart type"),
            children: [
              "🔮 ",
              O("chartAI.auto", "Auto")
            ]
          }
        ),
        m && /* @__PURE__ */ k(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__insights-btn",
            onClick: () => {
              A.length || K(), g(!I);
            },
            disabled: j,
            title: O("chartAI.showInsights", "Show data insights"),
            children: [
              "💡 ",
              O("chartAI.insights", "Insights")
            ]
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("div", { className: "nice-chart-ai__chart-wrapper", children: /* @__PURE__ */ e(
      De,
      {
        series: U,
        categories: Z,
        ...o
      }
    ) }),
    I && A.length > 0 && /* @__PURE__ */ k("div", { className: "nice-chart-ai__insights", children: [
      /* @__PURE__ */ k("div", { className: "nice-chart-ai__insights-header", children: [
        /* @__PURE__ */ k("h4", { children: [
          "💡 ",
          O("chartAI.dataInsights", "Data Insights")
        ] }),
        /* @__PURE__ */ e(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__insights-close",
            onClick: () => g(!1),
            children: "✕"
          }
        )
      ] }),
      /* @__PURE__ */ e("ul", { className: "nice-chart-ai__insights-list", children: A.map((D, P) => /* @__PURE__ */ k("li", { className: "nice-chart-ai__insight", children: [
        /* @__PURE__ */ e("span", { className: "nice-chart-ai__insight-icon", children: "•" }),
        D
      ] }, P)) }),
      /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights-footer", children: /* @__PURE__ */ k(
        "button",
        {
          type: "button",
          className: "nice-chart-ai__refresh",
          onClick: () => K(),
          disabled: j,
          children: [
            "🔄 ",
            O("chartAI.refresh", "Refresh")
          ]
        }
      ) })
    ] }),
    I && j && /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights nice-chart-ai__insights--loading", children: /* @__PURE__ */ k("div", { className: "nice-chart-ai__loading-content", children: [
      /* @__PURE__ */ e("span", { className: "nice-chart-ai__spinner" }),
      O("chartAI.generatingInsights", "Generating insights...")
    ] }) })
  ] });
});
function He(t, a) {
  const d = t ? typeof t == "number" ? new Date(t) : new Date(t) : /* @__PURE__ */ new Date(), c = (C) => C.toString().padStart(2, "0"), r = c(d.getHours()), u = c(d.getMinutes()), i = c(d.getSeconds()), m = d.getMilliseconds().toString().padStart(3, "0");
  switch (a) {
    case "HH:mm:ss":
      return `${r}:${u}:${i}`;
    case "HH:mm":
      return `${r}:${u}`;
    case "mm:ss":
      return `${u}:${i}`;
    case "ss.SSS":
      return `${i}.${m}`;
    case "ISO":
      return d.toISOString();
    default:
      return `${r}:${u}:${i}`;
  }
}
function Te(t) {
  if (t.length === 0) return null;
  const a = Math.min(...t), d = Math.max(...t), c = t.reduce((u, i) => u + i, 0) / t.length, r = t[t.length - 1];
  return { min: a, max: d, avg: c, current: r, count: t.length };
}
const Fe = ve(
  ({
    series: t,
    maxPoints: a = 100,
    slidingWindow: d = !0,
    refreshRate: c = 16,
    dataSource: r,
    width: u = 600,
    height: i = 400,
    title: m,
    showLegend: C = !0,
    showGrid: l = !0,
    yAxisLabel: v,
    xAxisLabel: f,
    stacked: S,
    zoomable: y,
    crosshair: p,
    annotations: o = [],
    legendInteractive: s,
    onDataPointClick: h,
    exportable: w,
    showControls: b = !0,
    showStatus: A = !0,
    initialPaused: N = !1,
    onDataReceived: I,
    onDataDropped: g,
    timeFormat: T = "HH:mm:ss",
    showStats: x,
    thresholds: O = [],
    className: B,
    style: R
  }, G) => {
    const [j, W] = ie(() => {
      const L = /* @__PURE__ */ new Map();
      for (const H of t)
        L.set(H.name, H.initialData?.slice() ?? []);
      return L;
    }), [U, Z] = ie([]), [X, K] = ie(N), [ee, he] = ie(!1), ne = be([]), D = be(Date.now()), P = be(null), re = te(() => {
      const L = ne.current;
      L.length !== 0 && (ne.current = [], W((H) => {
        const J = new Map(H);
        for (const pe of L) {
          const $ = J.get(pe.series);
          if (!$) continue;
          const E = [...$, pe.value];
          if (d && E.length > a) {
            const Y = E.length - a;
            g?.(Y, pe.series), E.splice(0, Y);
          }
          J.set(pe.series, E);
        }
        return J;
      }), L.length > 0 && Z((H) => {
        const J = [...H];
        for (const pe of L) {
          const $ = pe.category ?? He(pe.timestamp, T);
          J.push($);
        }
        return d && J.length > a && J.splice(0, J.length - a), J;
      }));
    }, [d, a, T, g]), F = te(() => {
      const L = Date.now();
      L - D.current >= c && (re(), D.current = L), P.current = requestAnimationFrame(F);
    }, [c, re]);
    $e(() => (X || (P.current = requestAnimationFrame(F)), () => {
      P.current !== null && (cancelAnimationFrame(P.current), P.current = null);
    }), [X, F]);
    const q = te(
      (L) => {
        if (X) return;
        const H = "points" in L ? L.points : [L];
        for (const J of H)
          j.has(J.series) && (ne.current.push(J), I?.(J));
      },
      [X, j, I]
    );
    $e(() => {
      if (!r) return;
      const L = r.subscribe(q);
      let H;
      return r.onStatusChange ? H = r.onStatusChange(he) : he(!0), r.fetchHistory && r.fetchHistory(a).then((J) => {
        for (const pe of J)
          ne.current.push(pe);
        re();
      }), () => {
        L(), H?.();
      };
    }, [r, q, a, re]);
    const de = me(() => t.map((L) => ({
      name: L.name,
      color: L.color,
      type: L.type,
      data: j.get(L.name) ?? []
    })), [t, j]), xe = me(() => {
      const L = [...o];
      for (const H of O)
        L.push({
          type: "line",
          value: H.value,
          color: H.color,
          label: H.label,
          dash: H.style === "dashed" ? "5,5" : H.style === "dotted" ? "2,2" : void 0
        });
      return L;
    }, [o, O]);
    Ie(
      G,
      () => ({
        pause() {
          K(!0);
        },
        resume() {
          K(!1);
        },
        isPaused() {
          return X;
        },
        clear() {
          W((L) => {
            const H = new Map(L);
            for (const J of H.keys())
              H.set(J, []);
            return H;
          }), Z([]), ne.current = [];
        },
        addPoint(L) {
          q(L);
        },
        addPoints(L) {
          q({ points: L });
        },
        getData(L) {
          return j.get(L) ?? [];
        },
        getCategories() {
          return U;
        },
        exportData() {
          return { series: de, categories: U };
        },
        getStats(L) {
          const H = j.get(L);
          return H ? Te(H) : null;
        }
      }),
      [X, j, U, de, q]
    );
    const ye = me(() => {
      if (!x) return null;
      const L = {};
      for (const [H, J] of j)
        L[H] = Te(J);
      return L;
    }, [x, j]);
    return /* @__PURE__ */ k("div", { className: B, style: { position: "relative", ...R }, children: [
      A && /* @__PURE__ */ k(
        "div",
        {
          style: {
            position: "absolute",
            top: 8,
            right: 8,
            display: "flex",
            alignItems: "center",
            gap: 4,
            fontSize: 12,
            color: ee ? "#22c55e" : "#ef4444",
            zIndex: 10
          },
          children: [
            /* @__PURE__ */ e(
              "span",
              {
                style: {
                  width: 8,
                  height: 8,
                  borderRadius: "50%",
                  backgroundColor: ee ? "#22c55e" : "#ef4444"
                }
              }
            ),
            ee ? "Live" : "Disconnected"
          ]
        }
      ),
      b && /* @__PURE__ */ e(
        "div",
        {
          style: {
            position: "absolute",
            top: 8,
            left: 8,
            display: "flex",
            gap: 4,
            zIndex: 10
          },
          children: /* @__PURE__ */ e(
            "button",
            {
              onClick: () => K((L) => !L),
              style: {
                padding: "4px 8px",
                fontSize: 12,
                border: "1px solid #ddd",
                borderRadius: 4,
                background: X ? "#fef3c7" : "#fff",
                cursor: "pointer"
              },
              title: X ? "Resume" : "Pause",
              children: X ? "▶" : "⏸"
            }
          )
        }
      ),
      x && ye && /* @__PURE__ */ e(
        "div",
        {
          style: {
            position: "absolute",
            bottom: 50,
            right: 8,
            background: "rgba(255,255,255,0.9)",
            border: "1px solid #ddd",
            borderRadius: 4,
            padding: 8,
            fontSize: 11,
            zIndex: 10
          },
          children: Object.entries(ye).map(
            ([L, H]) => H ? /* @__PURE__ */ k("div", { style: { marginBottom: 4 }, children: [
              /* @__PURE__ */ e("strong", { children: L }),
              /* @__PURE__ */ k("div", { children: [
                "Min: ",
                H.min.toFixed(2),
                " | Max: ",
                H.max.toFixed(2)
              ] }),
              /* @__PURE__ */ k("div", { children: [
                "Avg: ",
                H.avg.toFixed(2),
                " | Now: ",
                H.current.toFixed(2)
              ] })
            ] }, L) : null
          )
        }
      ),
      /* @__PURE__ */ e(
        De,
        {
          series: de,
          categories: U,
          width: u,
          height: i,
          title: m,
          showLegend: C,
          showGrid: l,
          yAxisLabel: v,
          xAxisLabel: f,
          stacked: S,
          zoomable: y,
          crosshair: p,
          annotations: xe,
          legendInteractive: s,
          onDataPointClick: h,
          exportable: w
        }
      )
    ] });
  }
);
Fe.displayName = "NiceLiveChart";
function at(t) {
  const {
    hubConnection: a,
    eventName: d = "DataPoint",
    subscribeMethod: c = "SubscribeToMetrics",
    historyMethod: r = "GetMetricHistory",
    metricName: u
  } = t;
  return {
    subscribe(i) {
      const m = (C) => {
        i(C);
      };
      return a.on(d, m), a.state === "Connected" && a.invoke(c, u).catch(() => {
      }), () => {
        a.off(d, m);
      };
    },
    async fetchHistory(i) {
      try {
        return await a.invoke(r, u, i);
      } catch {
        return [];
      }
    },
    onStatusChange(i) {
      const m = () => i(a.state === "Connected");
      return a.onclose(() => i(!1)), a.onreconnected(() => i(!0)), m(), () => {
      };
    }
  };
}
function ot(t) {
  const {
    url: a,
    autoReconnect: d = !0,
    reconnectDelay: c = 3e3,
    parseMessage: r = (v) => JSON.parse(v)
  } = t;
  let u = null, i = null, m = null, C = null;
  const l = () => {
    u = new WebSocket(a), u.onopen = () => {
      i?.(!0);
    }, u.onclose = () => {
      i?.(!1), d && (C = setTimeout(l, c));
    }, u.onerror = () => {
      u?.close();
    }, u.onmessage = (v) => {
      try {
        const f = r(v.data);
        f && m && m(f);
      } catch {
      }
    };
  };
  return {
    subscribe(v) {
      return m = v, l(), () => {
        m = null, C && clearTimeout(C), u?.close(), u = null;
      };
    },
    onStatusChange(v) {
      return i = v, () => {
        i = null;
      };
    }
  };
}
function st(t) {
  const {
    seriesNames: a,
    interval: d = 1e3,
    generateValue: c = () => Math.random() * 100
  } = t;
  let r = null, u = 0;
  return {
    subscribe(i) {
      return r = setInterval(() => {
        for (const m of a)
          i({
            series: m,
            value: c(m, u),
            timestamp: Date.now()
          });
        u++;
      }, d), () => {
        r && clearInterval(r);
      };
    },
    onStatusChange(i) {
      return i(!0), () => {
      };
    }
  };
}
const fe = ["#3b82f6", "#ef4444", "#22c55e", "#f59e0b", "#8b5cf6", "#ec4899", "#06b6d4", "#84cc16"], it = ({
  data: t,
  width: a = 400,
  height: d = 400,
  innerRadius: c = 0,
  title: r,
  showLegend: u = !0,
  showLabels: i = !0,
  className: m,
  style: C
}) => {
  const l = a / 2, v = (d - (u ? 30 : 0)) / 2 + (r ? 10 : 0), f = Math.min(l, v) - 40, S = t.reduce((o, s) => o + s.value, 0);
  let y = -Math.PI / 2;
  const p = t.map((o, s) => {
    const h = o.value / (S || 1) * Math.PI * 2, w = y;
    y += h;
    const b = y, A = (w + b) / 2, N = l + f * Math.cos(w), I = v + f * Math.sin(w), g = l + f * Math.cos(b), T = v + f * Math.sin(b), x = h > Math.PI ? 1 : 0, O = o.color || fe[s % fe.length];
    let B;
    if (c > 0) {
      const W = l + c * Math.cos(w), U = v + c * Math.sin(w), Z = l + c * Math.cos(b), X = v + c * Math.sin(b);
      B = `M${N},${I} A${f},${f} 0 ${x},1 ${g},${T} L${Z},${X} A${c},${c} 0 ${x},0 ${W},${U} Z`;
    } else
      B = `M${l},${v} L${N},${I} A${f},${f} 0 ${x},1 ${g},${T} Z`;
    const R = l + f * 0.7 * Math.cos(A), G = v + f * 0.7 * Math.sin(A), j = S > 0 ? Math.round(o.value / S * 100) : 0;
    return { ...o, path: B, labelX: R, labelY: G, pct: j, color: O };
  });
  return /* @__PURE__ */ e("div", { className: `nice-piechart ${m || ""}`, style: C, children: /* @__PURE__ */ k("svg", { width: a, height: d, className: "nice-piechart__svg", children: [
    r && /* @__PURE__ */ e("text", { x: l, y: 20, textAnchor: "middle", className: "nice-chart__title", children: r }),
    p.map((o, s) => /* @__PURE__ */ k("g", { children: [
      /* @__PURE__ */ e("path", { d: o.path, fill: o.color, stroke: "var(--bg-primary, #fff)", strokeWidth: 2, children: /* @__PURE__ */ e("title", { children: `${o.label}: ${o.value} (${o.pct}%)` }) }),
      i && o.pct >= 5 && /* @__PURE__ */ k("text", { x: o.labelX, y: o.labelY, textAnchor: "middle", dominantBaseline: "middle", className: "nice-piechart__label", children: [
        o.pct,
        "%"
      ] })
    ] }, s)),
    u && /* @__PURE__ */ e("g", { transform: `translate(10, ${d - 25})`, children: t.map((o, s) => /* @__PURE__ */ k("g", { transform: `translate(${s * 100}, 0)`, children: [
      /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: o.color || fe[s % fe.length] }),
      /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: o.label })
    ] }, s)) })
  ] }) });
}, lt = ({
  series: t,
  categories: a,
  width: d = 400,
  height: c = 400,
  maxValue: r,
  title: u,
  showLegend: i = !0,
  className: m,
  style: C
}) => {
  const l = d / 2, v = (c - (i ? 30 : 0)) / 2 + (u ? 10 : 0), f = Math.min(l, v) - 40, S = a.length, y = r ?? Math.max(...t.flatMap((h) => h.data), 1), p = Math.PI * 2 / S, o = 5, s = (h, w) => {
    const b = h * p - Math.PI / 2, A = w / y * f;
    return { x: l + A * Math.cos(b), y: v + A * Math.sin(b) };
  };
  return /* @__PURE__ */ e("div", { className: `nice-polarchart ${m || ""}`, style: C, children: /* @__PURE__ */ k("svg", { width: d, height: c, className: "nice-polarchart__svg", children: [
    u && /* @__PURE__ */ e("text", { x: l, y: 20, textAnchor: "middle", className: "nice-chart__title", children: u }),
    Array.from({ length: o }, (h, w) => {
      const b = f * ((w + 1) / o);
      return /* @__PURE__ */ e("circle", { cx: l, cy: v, r: b, fill: "none", stroke: "var(--border-color, #ddd)", strokeWidth: 0.5 }, w);
    }),
    a.map((h, w) => {
      const b = s(w, y), A = s(w, y * 1.12);
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("line", { x1: l, y1: v, x2: b.x, y2: b.y, stroke: "var(--border-color, #ddd)", strokeWidth: 0.5 }),
        /* @__PURE__ */ e("text", { x: A.x, y: A.y, textAnchor: "middle", dominantBaseline: "middle", className: "nice-chart__axis-label", children: h })
      ] }, w);
    }),
    t.map((h, w) => {
      const b = h.color || fe[w % fe.length], A = h.data.map((N, I) => {
        const g = s(I, N);
        return `${g.x},${g.y}`;
      }).join(" ");
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("polygon", { points: A, fill: h.fill !== !1 ? b : "none", fillOpacity: 0.15, stroke: b, strokeWidth: 2 }),
        h.data.map((N, I) => {
          const g = s(I, N);
          return /* @__PURE__ */ e("circle", { cx: g.x, cy: g.y, r: 3, fill: b, children: /* @__PURE__ */ e("title", { children: `${h.name} - ${a[I]}: ${N}` }) }, I);
        })
      ] }, h.name);
    }),
    i && /* @__PURE__ */ e("g", { transform: `translate(10, ${c - 25})`, children: t.map((h, w) => /* @__PURE__ */ k("g", { transform: `translate(${w * 100}, 0)`, children: [
      /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: h.color || fe[w % fe.length] }),
      /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: h.name })
    ] }, w)) })
  ] }) });
}, ht = ({
  value: t,
  min: a = 0,
  max: d = 100,
  width: c = 200,
  height: r = 200,
  startAngle: u = 225,
  endAngle: i = -45,
  color: m = "#3b82f6",
  trackColor: C,
  label: l,
  formatValue: v,
  ranges: f,
  className: S,
  style: y
}) => {
  const p = c / 2, o = r / 2, s = Math.min(p, o) - 20, h = Math.max(0, Math.min(1, (t - a) / (d - a || 1))), w = (x) => x * Math.PI / 180, b = (u - i + 360) % 360 || 360, A = (x) => ({
    x: p + s * Math.cos(w(x)),
    y: o - s * Math.sin(w(x))
  }), N = (x, O) => {
    const B = A(x), R = A(O), j = (x - O + 360) % 360 > 180 ? 1 : 0;
    return `M${B.x},${B.y} A${s},${s} 0 ${j},1 ${R.x},${R.y}`;
  }, I = u - h * b, g = A(I);
  let T = m;
  if (f) {
    for (const x of f)
      if (t >= x.start && t <= x.end) {
        T = x.color;
        break;
      }
  }
  return /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--circular ${S || ""}`, style: y, children: /* @__PURE__ */ k("svg", { width: c, height: r, children: [
    /* @__PURE__ */ e("path", { d: N(u, i), fill: "none", stroke: C || "var(--border-color, #e2e8f0)", strokeWidth: 12, strokeLinecap: "round" }),
    h > 0 && /* @__PURE__ */ e("path", { d: N(u, I), fill: "none", stroke: T, strokeWidth: 12, strokeLinecap: "round" }),
    /* @__PURE__ */ e("line", { x1: p, y1: o, x2: g.x, y2: g.y, stroke: "var(--text-primary, #333)", strokeWidth: 2, strokeLinecap: "round" }),
    /* @__PURE__ */ e("circle", { cx: p, cy: o, r: 4, fill: "var(--text-primary, #333)" }),
    /* @__PURE__ */ e("text", { x: p, y: o + s * 0.35, textAnchor: "middle", className: "nice-gauge__value", children: v ? v(t) : t }),
    l && /* @__PURE__ */ e("text", { x: p, y: o + s * 0.55, textAnchor: "middle", className: "nice-gauge__label", children: l })
  ] }) });
}, dt = ({
  value: t,
  min: a = 0,
  max: d = 100,
  width: c = 300,
  height: r = 60,
  orientation: u = "horizontal",
  color: i = "#3b82f6",
  label: m,
  formatValue: C,
  ranges: l,
  showTicks: v = !0,
  tickCount: f = 5,
  className: S,
  style: y
}) => {
  const p = u === "horizontal", o = p ? c - 40 : r - 40, s = Math.max(0, Math.min(1, (t - a) / (d - a || 1))), h = 10;
  let w = i;
  if (l) {
    for (const A of l)
      if (t >= A.start && t <= A.end) {
        w = A.color;
        break;
      }
  }
  const b = Array.from({ length: f }, (A, N) => a + (d - a) * (N / (f - 1)));
  return p ? /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--linear ${S || ""}`, style: y, children: /* @__PURE__ */ k("svg", { width: c, height: r, children: [
    m && /* @__PURE__ */ e("text", { x: c / 2, y: 14, textAnchor: "middle", className: "nice-gauge__label", children: m }),
    /* @__PURE__ */ e("rect", { x: 20, y: r / 2 - h / 2, width: o, height: h, rx: 5, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: 20, y: r / 2 - h / 2, width: o * s, height: h, rx: 5, fill: w }),
    /* @__PURE__ */ e("polygon", { points: `${20 + o * s},${r / 2 - h / 2 - 2} ${20 + o * s - 5},${r / 2 - h / 2 - 10} ${20 + o * s + 5},${r / 2 - h / 2 - 10}`, fill: "var(--text-primary, #333)" }),
    /* @__PURE__ */ e("text", { x: 20 + o * s, y: r / 2 - h / 2 - 12, textAnchor: "middle", className: "nice-gauge__value", style: { fontSize: 11 }, children: C ? C(t) : t }),
    v && b.map((A, N) => {
      const I = 20 + (A - a) / (d - a) * o;
      return /* @__PURE__ */ e("text", { x: I, y: r / 2 + h / 2 + 14, textAnchor: "middle", className: "nice-gauge__tick", children: A }, N);
    })
  ] }) }) : /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--linear nice-gauge--vertical ${S || ""}`, style: y, children: /* @__PURE__ */ k("svg", { width: c, height: r, children: [
    /* @__PURE__ */ e("rect", { x: c / 2 - h / 2, y: 20, width: h, height: o, rx: 5, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: c / 2 - h / 2, y: 20 + o * (1 - s), width: h, height: o * s, rx: 5, fill: w }),
    /* @__PURE__ */ e("text", { x: c / 2, y: 14, textAnchor: "middle", className: "nice-gauge__value", children: C ? C(t) : t }),
    m && /* @__PURE__ */ e("text", { x: c / 2, y: r - 4, textAnchor: "middle", className: "nice-gauge__label", children: m })
  ] }) });
}, ft = ({
  items: t,
  min: a = 0,
  max: d = 100,
  width: c = 300,
  height: r = 300,
  startAngle: u = 225,
  endAngle: i = -45,
  formatValue: m,
  title: C,
  className: l,
  style: v
}) => {
  const f = c / 2, S = r / 2, y = Math.min(f, S) - 30, p = Math.min(20, y / (t.length + 1)), o = 4, s = (b) => b * Math.PI / 180, h = (u - i + 360) % 360 || 360, w = (b, A, N) => {
    const I = f + b * Math.cos(s(A)), g = S - b * Math.sin(s(A)), T = f + b * Math.cos(s(N)), x = S - b * Math.sin(s(N)), O = (A - N + 360) % 360;
    return `M${I},${g} A${b},${b} 0 ${O > 180 ? 1 : 0},1 ${T},${x}`;
  };
  return /* @__PURE__ */ e("div", { className: `nice-bargauge ${l || ""}`, style: v, children: /* @__PURE__ */ k("svg", { width: c, height: r, children: [
    C && /* @__PURE__ */ e("text", { x: f, y: 20, textAnchor: "middle", className: "nice-chart__title", children: C }),
    t.map((b, A) => {
      const N = y - A * (p + o), I = Math.max(0, Math.min(1, (b.value - a) / (d - a || 1))), g = u - I * h, T = b.color || fe[A % fe.length];
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("path", { d: w(N, u, i), fill: "none", stroke: "var(--border-color, #e2e8f0)", strokeWidth: p, strokeLinecap: "round" }),
        I > 0 && /* @__PURE__ */ e("path", { d: w(N, u, g), fill: "none", stroke: T, strokeWidth: p, strokeLinecap: "round" })
      ] }, A);
    }),
    /* @__PURE__ */ e("g", { children: t.map((b, A) => /* @__PURE__ */ k("text", { x: f, y: S - ((t.length - 1) / 2 - A) * 16, textAnchor: "middle", dominantBaseline: "middle", className: "nice-gauge__value", style: { fontSize: 12 }, children: [
      b.label ? `${b.label}: ` : "",
      m ? m(b.value) : b.value
    ] }, A)) })
  ] }) });
}, ut = ({
  data: t,
  width: a = 120,
  height: d = 30,
  type: c = "line",
  color: r = "#3b82f6",
  showMinMax: u,
  showLastPoint: i = !0,
  className: m,
  style: C
}) => {
  if (t.length === 0) return null;
  const l = 2, v = Math.min(...t), f = Math.max(...t), S = f - v || 1, y = a - l * 2, p = d - l * 2, o = (N) => l + N / (t.length - 1 || 1) * y, s = (N) => l + p - (N - v) / S * p;
  if (c === "bar") {
    const N = Math.max(1, y / t.length - 1);
    return /* @__PURE__ */ e("svg", { width: a, height: d, className: `nice-sparkline ${m || ""}`, style: C, children: t.map((I, g) => /* @__PURE__ */ e("rect", { x: l + g / t.length * y, y: s(I), width: N, height: p - (s(I) - l), fill: r, rx: 1 }, g)) });
  }
  const h = t.map((N, I) => `${o(I)},${s(N)}`).join(" "), w = t.indexOf(v), b = t.indexOf(f), A = t.length - 1;
  return /* @__PURE__ */ k("svg", { width: a, height: d, className: `nice-sparkline ${m || ""}`, style: C, children: [
    c === "area" && /* @__PURE__ */ e("polygon", { points: `${o(0)},${l + p} ${h} ${o(A)},${l + p}`, fill: r, opacity: 0.15 }),
    /* @__PURE__ */ e("polyline", { points: h, fill: "none", stroke: r, strokeWidth: 1.5 }),
    u && /* @__PURE__ */ e("circle", { cx: o(w), cy: s(v), r: 2, fill: "#ef4444" }),
    u && /* @__PURE__ */ e("circle", { cx: o(b), cy: s(f), r: 2, fill: "#22c55e" }),
    i && /* @__PURE__ */ e("circle", { cx: o(A), cy: s(t[A]), r: 2, fill: r })
  ] });
}, mt = ({
  value: t,
  target: a,
  min: d = 0,
  max: c = 100,
  width: r = 200,
  height: u = 30,
  color: i = "#3b82f6",
  targetColor: m = "#ef4444",
  className: C,
  style: l
}) => {
  const f = r - 8, S = u - 8, y = Math.max(0, Math.min(1, (t - d) / (c - d || 1))), p = a != null ? Math.max(0, Math.min(1, (a - d) / (c - d || 1))) : null;
  return /* @__PURE__ */ k("svg", { width: r, height: u, className: `nice-bullet ${C || ""}`, style: l, children: [
    /* @__PURE__ */ e("rect", { x: 4, y: 4, width: f, height: S, rx: 3, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: 4, y: 4 + S * 0.2, width: f * y, height: S * 0.6, rx: 2, fill: i }),
    p != null && /* @__PURE__ */ e("line", { x1: 4 + f * p, y1: 6, x2: 4 + f * p, y2: 4 + S - 2, stroke: m, strokeWidth: 2 })
  ] });
}, pt = ({
  data: t,
  width: a = 400,
  height: d = 300,
  inverted: c,
  showLabels: r = !0,
  showValues: u = !0,
  title: i,
  className: m,
  style: C
}) => {
  const l = { top: i ? 30 : 10, bottom: 10, x: 40 }, v = a - l.x * 2, f = d - l.top - l.bottom, S = c ? [...t].reverse() : t, y = Math.max(...S.map((o) => o.value), 1), p = f / S.length;
  return /* @__PURE__ */ e("div", { className: `nice-funnel ${m || ""}`, style: C, children: /* @__PURE__ */ k("svg", { width: a, height: d, children: [
    i && /* @__PURE__ */ e("text", { x: a / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: i }),
    S.map((o, s) => {
      const h = o.value / y * v, w = s < S.length - 1 ? S[s + 1].value / y * v : h * 0.3, b = l.top + s * p, A = b + p, N = a / 2, I = `${N - h / 2},${b} ${N + h / 2},${b} ${N + w / 2},${A} ${N - w / 2},${A}`, g = o.color || fe[s % fe.length];
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("polygon", { points: I, fill: g, stroke: "var(--bg-primary, #fff)", strokeWidth: 1, children: /* @__PURE__ */ e("title", { children: `${o.label}: ${o.value}` }) }),
        r && /* @__PURE__ */ e("text", { x: N, y: b + p / 2 - (u ? 4 : 0), textAnchor: "middle", dominantBaseline: "middle", className: "nice-funnel__label", children: o.label }),
        u && /* @__PURE__ */ e("text", { x: N, y: b + p / 2 + 10, textAnchor: "middle", dominantBaseline: "middle", className: "nice-funnel__value", children: o.value })
      ] }, s);
    })
  ] }) });
}, Ee = ({
  nodes: t,
  links: a,
  width: d = 600,
  height: c = 400,
  nodeWidth: r = 20,
  nodePadding: u = 10,
  title: i,
  className: m,
  style: C
}) => {
  const l = { top: i ? 40 : 20, bottom: 20, left: 20, right: 20 }, v = d - l.left - l.right, f = c - l.top - l.bottom, S = new Set(a.map((x) => x.source)), y = new Set(a.map((x) => x.target)), p = t.filter((x) => S.has(x.id) && !y.has(x.id)), o = t.filter((x) => y.has(x.id)), s = t.filter((x) => S.has(x.id) && y.has(x.id)), h = [p, ...s.length ? [s] : [], o].filter((x) => x.length > 0), w = h.length, b = /* @__PURE__ */ new Map();
  t.forEach((x) => {
    const O = a.filter((R) => R.source === x.id).reduce((R, G) => R + G.value, 0), B = a.filter((R) => R.target === x.id).reduce((R, G) => R + G.value, 0);
    b.set(x.id, Math.max(O, B));
  });
  const A = h.map((x) => x.reduce((O, B) => O + (b.get(B.id) || 0), 0) + (x.length - 1) * u), N = Math.max(...A, 1), I = /* @__PURE__ */ new Map();
  h.forEach((x, O) => {
    const B = l.left + O / (w - 1 || 1) * (v - r);
    let R = 0;
    x.forEach((G) => {
      const j = (b.get(G.id) || 0) / N * f;
      I.set(G.id, { x: B, y: l.top + R, h: j }), R += j + u;
    });
  });
  const g = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
  return t.forEach((x) => {
    g.set(x.id, 0), T.set(x.id, 0);
  }), /* @__PURE__ */ e("div", { className: `nice-sankey ${m || ""}`, style: C, children: /* @__PURE__ */ k("svg", { width: d, height: c, children: [
    i && /* @__PURE__ */ e("text", { x: d / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: i }),
    a.map((x, O) => {
      const B = I.get(x.source), R = I.get(x.target);
      if (!B || !R) return null;
      const G = g.get(x.source) || 0, j = T.get(x.target) || 0, W = x.value / N * f;
      g.set(x.source, G + W), T.set(x.target, j + W);
      const U = B.x + r, Z = B.y + G, X = R.x, K = R.y + j, ee = (U + X) / 2, ne = t.find((D) => D.id === x.source)?.color || fe[O % fe.length];
      return /* @__PURE__ */ e(
        "path",
        {
          d: `M${U},${Z} C${ee},${Z} ${ee},${K} ${X},${K} L${X},${K + W} C${ee},${K + W} ${ee},${Z + W} ${U},${Z + W} Z`,
          fill: ne,
          fillOpacity: 0.3,
          stroke: ne,
          strokeOpacity: 0.5,
          strokeWidth: 0.5,
          children: /* @__PURE__ */ e("title", { children: `${x.source} → ${x.target}: ${x.value}` })
        },
        O
      );
    }),
    t.map((x, O) => {
      const B = I.get(x.id);
      if (!B) return null;
      const R = x.color || fe[O % fe.length];
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("rect", { x: B.x, y: B.y, width: r, height: Math.max(B.h, 2), fill: R, rx: 2 }),
        /* @__PURE__ */ e(
          "text",
          {
            x: B.x < v / 2 ? B.x + r + 4 : B.x - 4,
            y: B.y + B.h / 2,
            textAnchor: B.x < v / 2 ? "start" : "end",
            dominantBaseline: "middle",
            className: "nice-chart__legend-text",
            children: x.label
          }
        )
      ] }, x.id);
    })
  ] }) });
}, gt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceSankey: Ee
}, Symbol.toStringTag, { value: "Module" })), xt = ({
  data: t,
  min: a,
  max: d,
  start: c,
  end: r,
  onChange: u,
  width: i = 500,
  height: m = 100,
  step: C = 1,
  formatValue: l,
  chartColor: v = "#3b82f6",
  className: f,
  style: S
}) => {
  const y = { top: 10, bottom: 30, left: 10, right: 10 }, p = i - y.left - y.right, o = m - y.top - y.bottom, s = (I) => y.left + (I - a) / (d - a || 1) * p, h = (I) => {
    const g = Math.max(0, Math.min(1, (I - y.left) / p)), T = a + g * (d - a);
    return Math.round(T / C) * C;
  }, w = (I, g) => {
    g.preventDefault();
    const T = g.target.closest("svg");
    if (!T) return;
    const x = (B) => {
      const R = T.getBoundingClientRect(), G = h(B.clientX - R.left);
      I === "start" ? u(Math.min(G, r), r) : u(c, Math.max(G, c));
    }, O = () => {
      document.removeEventListener("pointermove", x), document.removeEventListener("pointerup", O);
    };
    document.addEventListener("pointermove", x), document.addEventListener("pointerup", O);
  }, b = t ? Math.min(...t) : 0, N = (t ? Math.max(...t) : 1) - b || 1;
  return /* @__PURE__ */ e("div", { className: `nice-rangeselector ${f || ""}`, style: S, children: /* @__PURE__ */ k("svg", { width: i, height: m, children: [
    t && t.length > 1 && /* @__PURE__ */ e(
      "polygon",
      {
        points: `${y.left},${y.top + o} ${t.map((I, g) => `${y.left + g / (t.length - 1) * p},${y.top + o - (I - b) / N * o}`).join(" ")} ${y.left + p},${y.top + o}`,
        fill: v,
        opacity: 0.15
      }
    ),
    /* @__PURE__ */ e("rect", { x: s(c), y: y.top, width: s(r) - s(c), height: o, fill: v, opacity: 0.1 }),
    /* @__PURE__ */ e("rect", { x: y.left, y: y.top, width: s(c) - y.left, height: o, fill: "var(--bg-secondary, #f5f5f5)", opacity: 0.6 }),
    /* @__PURE__ */ e("rect", { x: s(r), y: y.top, width: y.left + p - s(r), height: o, fill: "var(--bg-secondary, #f5f5f5)", opacity: 0.6 }),
    /* @__PURE__ */ e(
      "rect",
      {
        x: s(c) - 4,
        y: y.top,
        width: 8,
        height: o,
        fill: v,
        rx: 2,
        cursor: "ew-resize",
        onPointerDown: (I) => w("start", I)
      }
    ),
    /* @__PURE__ */ e(
      "rect",
      {
        x: s(r) - 4,
        y: y.top,
        width: 8,
        height: o,
        fill: v,
        rx: 2,
        cursor: "ew-resize",
        onPointerDown: (I) => w("end", I)
      }
    ),
    /* @__PURE__ */ e("text", { x: s(c), y: y.top + o + 18, textAnchor: "middle", className: "nice-chart__axis-label", children: l ? l(c) : c }),
    /* @__PURE__ */ e("text", { x: s(r), y: y.top + o + 18, textAnchor: "middle", className: "nice-chart__axis-label", children: l ? l(r) : r })
  ] }) });
}, Ye = ({
  regions: t,
  width: a = 600,
  height: d = 400,
  viewBox: c = "0 0 1000 600",
  colorRange: r = ["#dbeafe", "#1d4ed8"],
  maxValue: u,
  onRegionClick: i,
  selectedRegionId: m,
  title: C,
  showTooltip: l = !0,
  className: v,
  style: f
}) => {
  const S = u ?? Math.max(...t.map((p) => p.value ?? 0), 1), y = (p) => {
    const o = (x) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)], [s, h, w] = o(r[0]), [b, A, N] = o(r[1]), I = Math.round(s + (b - s) * p), g = Math.round(h + (A - h) * p), T = Math.round(w + (N - w) * p);
    return `rgb(${I},${g},${T})`;
  };
  return /* @__PURE__ */ k("div", { className: `nice-vectormap ${v || ""}`, style: f, children: [
    C && /* @__PURE__ */ e("div", { className: "nice-vectormap__title", children: C }),
    /* @__PURE__ */ e("svg", { width: a, height: d, viewBox: c, children: t.map((p) => {
      const o = p.value != null ? Math.max(0, Math.min(1, p.value / S)) : 0, s = p.value != null ? y(o) : "var(--bg-tertiary, #e5e7eb)", h = p.id === m;
      return /* @__PURE__ */ e(
        "path",
        {
          d: p.path,
          fill: s,
          stroke: h ? "var(--color-primary, #3b82f6)" : "var(--border-color, #d1d5db)",
          strokeWidth: h ? 2 : 0.5,
          cursor: i ? "pointer" : void 0,
          onClick: () => i?.(p),
          children: l && /* @__PURE__ */ e("title", { children: `${p.name}${p.value != null ? `: ${p.value}` : ""}` })
        },
        p.id
      );
    }) })
  ] });
}, yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceVectorMap: Ye
}, Symbol.toStringTag, { value: "Module" })), Ve = `
.nice-forecast-chart {
  display: flex;
  flex-direction: column;
  background: var(--nice-bg-primary, #ffffff);
  border: 1px solid var(--nice-border-color, #e5e7eb);
  border-radius: 0.5rem;
  overflow: hidden;
}

.nice-forecast-chart__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
}

.nice-forecast-chart__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--nice-text-primary);
  margin: 0;
}

.nice-forecast-chart__actions {
  display: flex;
  gap: 0.5rem;
}

.nice-forecast-chart__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--nice-border-color, #d1d5db);
  background: var(--nice-bg-primary, #ffffff);
  color: var(--nice-text-secondary);
}

.nice-forecast-chart__btn:hover {
  background: var(--nice-bg-hover, #f3f4f6);
  color: var(--nice-text-primary);
}

.nice-forecast-chart__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nice-forecast-chart__container {
  position: relative;
  width: 100%;
  padding: 1rem;
}

.nice-forecast-chart__svg {
  width: 100%;
  overflow: visible;
}

.nice-forecast-chart__grid-line {
  stroke: var(--nice-border-divider, #f3f4f6);
  stroke-width: 1;
}

.nice-forecast-chart__axis-line {
  stroke: var(--nice-border-color, #e5e7eb);
  stroke-width: 1;
}

.nice-forecast-chart__axis-label {
  font-size: 0.6875rem;
  fill: var(--nice-text-secondary);
}

.nice-forecast-chart__axis-title {
  font-size: 0.75rem;
  font-weight: 500;
  fill: var(--nice-text-primary);
}

.nice-forecast-chart__historical-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nice-forecast-chart__forecast-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 6, 4;
}

.nice-forecast-chart__confidence-band {
  opacity: 0.2;
}

.nice-forecast-chart__forecast-region {
  fill: var(--nice-bg-secondary, #f9fafb);
  opacity: 0.5;
}

.nice-forecast-chart__point {
  cursor: pointer;
  transition: r 0.15s ease;
}

.nice-forecast-chart__point:hover {
  r: 6;
}

.nice-forecast-chart__annotation-line {
  stroke-dasharray: 4, 2;
  stroke-width: 1;
}

.nice-forecast-chart__annotation-marker {
  cursor: pointer;
  transition: transform 0.15s ease;
}

.nice-forecast-chart__annotation-marker:hover {
  transform: scale(1.2);
}

.nice-forecast-chart__reference-line {
  stroke-width: 1;
}

.nice-forecast-chart__reference-label {
  font-size: 0.625rem;
  fill: var(--nice-text-secondary);
}

.nice-forecast-chart__cash-runway {
  pointer-events: none;
}

.nice-forecast-chart__cash-runway-line {
  stroke: #ef4444;
  stroke-width: 2;
  stroke-dasharray: 8, 4;
}

.nice-forecast-chart__cash-runway-label-bg {
  fill: #ef4444;
  rx: 4;
}

.nice-forecast-chart__cash-runway-label {
  font-size: 0.6875rem;
  font-weight: 600;
  fill: #ffffff;
}

.nice-forecast-chart__cash-runway-date {
  font-size: 0.625rem;
  fill: #ef4444;
  font-weight: 500;
}

.nice-forecast-chart__tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 100;
  padding: 0.75rem;
  background: var(--nice-bg-primary, #ffffff);
  border: 1px solid var(--nice-border-color, #e5e7eb);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-size: 0.8125rem;
  max-width: 250px;
}

.nice-forecast-chart__tooltip-date {
  font-weight: 600;
  color: var(--nice-text-primary);
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
}

.nice-forecast-chart__tooltip-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.nice-forecast-chart__tooltip-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.nice-forecast-chart__tooltip-label {
  color: var(--nice-text-secondary);
  flex: 1;
}

.nice-forecast-chart__tooltip-value {
  font-weight: 600;
  color: var(--nice-text-primary);
  font-variant-numeric: tabular-nums;
}

.nice-forecast-chart__tooltip-confidence {
  font-size: 0.75rem;
  color: var(--nice-text-tertiary);
}

.nice-forecast-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--nice-border-color, #e5e7eb);
}

.nice-forecast-chart__legend-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--nice-text-secondary);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}

.nice-forecast-chart__legend-item:hover {
  color: var(--nice-text-primary);
}

.nice-forecast-chart__legend-item--hidden {
  opacity: 0.4;
}

.nice-forecast-chart__legend-color {
  width: 16px;
  height: 3px;
  border-radius: 1px;
}

.nice-forecast-chart__legend-color--dashed {
  background: repeating-linear-gradient(
    90deg,
    currentColor,
    currentColor 4px,
    transparent 4px,
    transparent 6px
  );
}

.nice-forecast-chart__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: var(--nice-text-secondary);
}

/* Dark mode */
.dark .nice-forecast-chart {
  background: var(--nice-bg-primary-dark, #111827);
  border-color: var(--nice-border-color-dark, #374151);
}

.dark .nice-forecast-chart__tooltip {
  background: var(--nice-bg-secondary-dark, #1f2937);
  border-color: var(--nice-border-color-dark, #374151);
}

.dark .nice-forecast-chart__forecast-region {
  fill: var(--nice-bg-secondary-dark, #1f2937);
}
`, ze = [
  "#3b82f6",
  // blue
  "#10b981",
  // green
  "#f59e0b",
  // amber
  "#ef4444",
  // red
  "#8b5cf6",
  // purple
  "#ec4899",
  // pink
  "#06b6d4",
  // cyan
  "#f97316"
  // orange
];
function le(t) {
  return t instanceof Date ? t : new Date(t);
}
function Ae(t, a = "pl-PL") {
  return t.toLocaleDateString(a, {
    year: "numeric",
    month: "short",
    day: "numeric"
  });
}
function Me(t, a = "pl-PL") {
  return new Intl.NumberFormat(a, {
    minimumFractionDigits: 0,
    maximumFractionDigits: 2
  }).format(t);
}
const _t = ve(
  function(a, d) {
    const {
      scenarios: c,
      annotations: r = [],
      referenceLines: u = [],
      forecastStartDate: i,
      cashRunway: m,
      xAxis: C,
      yAxis: l,
      confidenceBands: v = [{ level: 95, color: "#3b82f6", opacity: 0.15 }],
      tooltip: f,
      legend: S = { enabled: !0, position: "bottom", interactive: !0 },
      height: y = 350,
      showForecastRegion: p = !0,
      lineWidth: o = 2,
      showPoints: s = !1,
      pointRadius: h = 4,
      enableZoom: w = !1,
      animationDuration: b = 300,
      responsive: A = !0,
      onPointClick: N,
      onAnnotationClick: I,
      onScenarioToggle: g,
      onViewportChange: T,
      size: x = "medium",
      disabled: O = !1,
      labels: B = {},
      locale: R = "pl-PL",
      className: G,
      style: j
    } = a, [W, U] = ie(
      () => c.map((n, M) => ({
        ...n,
        color: n.color ?? ze[M % ze.length],
        visible: n.visible !== !1
      }))
    ), [Z, X] = ie(null), [K, ee] = ie({ x: 0, y: 0 }), he = be(null), ne = be(null), D = { top: 20, right: 30, bottom: 40, left: 60 }, [P, re] = ie({
      width: 600,
      height: typeof y == "number" ? y : 350
    });
    $e(() => {
      if (!A || !he.current) return;
      const n = new ResizeObserver((M) => {
        for (const z of M)
          re((_) => ({
            width: z.contentRect.width,
            height: _.height
          }));
      });
      return n.observe(he.current), () => n.disconnect();
    }, [A]), $e(() => {
      const n = "nice-forecast-chart-styles";
      if (!document.getElementById(n)) {
        const M = document.createElement("style");
        M.id = n, M.textContent = Ve, document.head.appendChild(M);
      }
    }, []);
    const { xScale: F, yScale: q, allDates: de, minY: xe, maxY: ye } = me(() => {
      const M = W.filter((Q) => Q.visible !== !1).flatMap((Q) => Q.data);
      if (M.length === 0)
        return { xScale: () => 0, yScale: () => 0, allDates: [], minY: 0, maxY: 100 };
      const z = M.map((Q) => le(Q.date).getTime()), _ = Math.min(...z), V = Math.max(...z), ae = M.flatMap((Q) => [Q.value, Q.forecast, Q.lowerBound, Q.upperBound]).filter((Q) => Q != null), ue = l?.min ?? Math.min(...ae) * 0.95, se = l?.max ?? Math.max(...ae) * 1.05, ge = P.width - D.left - D.right, _e = P.height - D.top - D.bottom, we = (Q) => {
        const Ce = typeof Q == "number" ? Q : Q.getTime();
        return D.left + (Ce - _) / (V - _) * ge;
      }, Se = (Q) => D.top + _e - (Q - ue) / (se - ue) * _e, Oe = [...new Set(z)].sort((Q, Ce) => Q - Ce).map((Q) => new Date(Q));
      return {
        xScale: we,
        yScale: Se,
        allDates: Oe,
        minY: ue,
        maxY: se
      };
    }, [W, P, D, l]), L = i ? le(i) : null, H = me(() => {
      if (!m?.enabled) return null;
      const n = m.threshold ?? 0, M = m.scenarioId ? W.find((_) => _.id === m.scenarioId && _.visible !== !1) : W.find((_) => _.visible !== !1);
      if (!M) return null;
      const z = M.data.sort(
        (_, V) => le(_.date).getTime() - le(V.date).getTime()
      );
      for (let _ = 1; _ < z.length; _++) {
        const V = z[_ - 1], ae = z[_], ue = V.forecast ?? V.value, se = ae.forecast ?? ae.value;
        if (ue != null && se != null && ue > n && se <= n) {
          const ge = (ue - n) / (ue - se), _e = le(V.date).getTime(), we = le(ae.date).getTime(), Se = _e + ge * (we - _e);
          return new Date(Se);
        }
      }
      return null;
    }, [m, W]), J = te(
      (n, M) => {
        const z = n.filter((_) => _[M] != null).map((_) => ({ x: F(le(_.date)), y: q(_[M]) }));
        return z.length === 0 ? "" : `M ${z.map((_) => `${_.x},${_.y}`).join(" L ")}`;
      },
      [F, q]
    ), pe = te(
      (n) => {
        const M = n.filter((V) => V.lowerBound != null && V.upperBound != null);
        if (M.length === 0) return "";
        const z = M.map((V) => ({
          x: F(le(V.date)),
          y: q(V.upperBound)
        })), _ = M.map((V) => ({ x: F(le(V.date)), y: q(V.lowerBound) })).reverse();
        return `M ${z.map((V) => `${V.x},${V.y}`).join(" L ")} L ${_.map((V) => `${V.x},${V.y}`).join(" L ")} Z`;
      },
      [F, q]
    ), $ = te(
      (n) => {
        if (!ne.current || f?.enabled === !1) return;
        const M = ne.current.getBoundingClientRect(), z = n.clientX - M.left;
        n.clientY - M.top;
        let _ = null, V = 1 / 0;
        for (const ae of de) {
          const ue = F(ae), se = Math.abs(ue - z);
          se < V && (V = se, _ = ae);
        }
        if (_ && V < 50) {
          const ae = W.filter((se) => se.visible !== !1).map((se) => {
            const ge = se.data.find((_e) => le(_e.date).getTime() === _.getTime());
            return {
              scenario: se,
              value: ge?.value,
              forecast: ge?.forecast,
              lowerBound: ge?.lowerBound,
              upperBound: ge?.upperBound
            };
          }), ue = r.filter(
            (se) => Math.abs(le(se.date).getTime() - _.getTime()) < 864e5
          );
          X({ date: _, values: ae, annotations: ue }), ee({ x: n.clientX - M.left + 10, y: n.clientY - M.top - 10 });
        } else
          X(null);
      },
      [F, de, W, r, f]
    ), E = te(
      (n) => {
        if (!S.interactive) return;
        U((z) => z.map((_) => _.id === n ? { ..._, visible: !_.visible } : _));
        const M = W.find((z) => z.id === n);
        M && g?.(n, !M.visible);
      },
      [S.interactive, W, g]
    );
    Ie(
      d,
      () => ({
        getScenarios: () => W,
        updateScenario: (n, M) => {
          U((z) => z.map((_) => _.id === n ? { ..._, data: M } : _));
        },
        toggleScenario: E,
        setZoomRange: () => {
        },
        // Would need pan/zoom implementation
        resetZoom: () => {
        },
        exportImage: (n) => {
          if (!ne.current) return null;
          const M = ne.current, _ = new XMLSerializer().serializeToString(M);
          return `data:image/svg+xml;base64,${btoa(_)}`;
        },
        getDataAtDate: (n) => {
          const M = W.filter((z) => z.visible !== !1).map((z) => {
            const _ = z.data.find((V) => le(V.date).getTime() === n.getTime());
            return {
              scenario: z,
              value: _?.value,
              forecast: _?.forecast,
              lowerBound: _?.lowerBound,
              upperBound: _?.upperBound
            };
          });
          return {
            date: n,
            values: M,
            annotations: r.filter((z) => le(z.date).getTime() === n.getTime())
          };
        }
      }),
      [W, r, E]
    ), P.width - D.left - D.right;
    const Y = P.height - D.top - D.bottom, ce = me(() => {
      const n = l?.tickCount ?? 5, M = [], z = (ye - xe) / (n - 1);
      for (let _ = 0; _ < n; _++)
        M.push(xe + z * _);
      return M;
    }, [xe, ye, l?.tickCount]), oe = me(() => {
      const n = C?.tickCount ?? 6;
      if (de.length === 0) return [];
      const M = Math.max(1, Math.floor(de.length / (n - 1)));
      return de.filter((z, _) => _ % M === 0 || _ === de.length - 1);
    }, [de, C?.tickCount]);
    return W.length === 0 || W.every((n) => n.data.length === 0) ? /* @__PURE__ */ e("div", { className: `nice-forecast-chart ${G ?? ""}`, style: j, children: /* @__PURE__ */ e("div", { className: "nice-forecast-chart__empty", children: B.noData ?? "No data available" }) }) : /* @__PURE__ */ k("div", { className: `nice-forecast-chart ${G ?? ""}`, style: { ...j, height: y }, children: [
      /* @__PURE__ */ k("div", { ref: he, className: "nice-forecast-chart__container", children: [
        /* @__PURE__ */ k(
          "svg",
          {
            ref: ne,
            className: "nice-forecast-chart__svg",
            width: P.width,
            height: P.height,
            onMouseMove: $,
            onMouseLeave: () => X(null),
            children: [
              l?.showGrid !== !1 && ce.map((n) => /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__grid-line",
                  x1: D.left,
                  x2: P.width - D.right,
                  y1: q(n),
                  y2: q(n)
                },
                n
              )),
              p && L && /* @__PURE__ */ e(
                "rect",
                {
                  className: "nice-forecast-chart__forecast-region",
                  x: F(L),
                  y: D.top,
                  width: P.width - D.right - F(L),
                  height: Y
                }
              ),
              u.map((n) => /* @__PURE__ */ k("g", { children: [
                /* @__PURE__ */ e(
                  "line",
                  {
                    className: "nice-forecast-chart__reference-line",
                    x1: D.left,
                    x2: P.width - D.right,
                    y1: q(n.value),
                    y2: q(n.value),
                    stroke: n.color ?? "#9ca3af",
                    strokeDasharray: n.dashArray ?? "4,2"
                  }
                ),
                n.label && /* @__PURE__ */ e(
                  "text",
                  {
                    className: "nice-forecast-chart__reference-label",
                    x: P.width - D.right - 4,
                    y: q(n.value) - 4,
                    textAnchor: "end",
                    children: n.label
                  }
                )
              ] }, n.id)),
              H && m?.enabled && /* @__PURE__ */ k("g", { className: "nice-forecast-chart__cash-runway", children: [
                /* @__PURE__ */ e(
                  "line",
                  {
                    className: "nice-forecast-chart__cash-runway-line",
                    x1: F(H),
                    x2: F(H),
                    y1: D.top,
                    y2: P.height - D.bottom,
                    stroke: m.color ?? "#ef4444"
                  }
                ),
                m.showLabel !== !1 && /* @__PURE__ */ k(Be, { children: [
                  /* @__PURE__ */ e(
                    "rect",
                    {
                      className: "nice-forecast-chart__cash-runway-label-bg",
                      x: F(H) - 60,
                      y: D.top - 2,
                      width: 120,
                      height: m.showDate !== !1 ? 32 : 20,
                      fill: m.color ?? "#ef4444",
                      rx: 4
                    }
                  ),
                  /* @__PURE__ */ e(
                    "text",
                    {
                      className: "nice-forecast-chart__cash-runway-label",
                      x: F(H),
                      y: D.top + 12,
                      textAnchor: "middle",
                      fill: "#ffffff",
                      children: m.label ?? B.cashRunsOut ?? "💰 Cash runs out"
                    }
                  ),
                  m.showDate !== !1 && /* @__PURE__ */ e(
                    "text",
                    {
                      className: "nice-forecast-chart__cash-runway-label",
                      x: F(H),
                      y: D.top + 26,
                      textAnchor: "middle",
                      fill: "#ffffff",
                      style: { fontSize: "0.625rem", opacity: 0.9 },
                      children: Ae(H, R)
                    }
                  )
                ] })
              ] }),
              W.filter((n) => n.visible !== !1 && n.showConfidenceBand).map((n) => /* @__PURE__ */ e(
                "path",
                {
                  className: "nice-forecast-chart__confidence-band",
                  d: pe(n.data),
                  fill: n.color
                },
                `band-${n.id}`
              )),
              W.filter((n) => n.visible !== !1).map((n) => {
                const M = L ? n.data.filter((_) => le(_.date) < L) : n.data.filter((_) => _.value != null), z = L ? n.data.filter((_) => le(_.date) >= L) : n.data.filter((_) => _.forecast != null);
                return /* @__PURE__ */ k("g", { children: [
                  /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__historical-line",
                      d: J(M, "value"),
                      stroke: n.color,
                      strokeWidth: o
                    }
                  ),
                  /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__forecast-line",
                      d: J(z, L ? "value" : "forecast"),
                      stroke: n.color,
                      strokeWidth: o
                    }
                  ),
                  z.length > 0 && n.data.some((_) => _.forecast != null) && /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__forecast-line",
                      d: J(n.data, "forecast"),
                      stroke: n.color,
                      strokeWidth: o
                    }
                  ),
                  s && n.data.map((_, V) => {
                    const ae = _.value ?? _.forecast;
                    return ae == null ? null : /* @__PURE__ */ e(
                      "circle",
                      {
                        className: "nice-forecast-chart__point",
                        cx: F(le(_.date)),
                        cy: q(ae),
                        r: h,
                        fill: n.color,
                        onClick: () => N?.(_, n)
                      },
                      V
                    );
                  })
                ] }, n.id);
              }),
              r.map((n) => {
                const M = F(le(n.date));
                return /* @__PURE__ */ k(
                  "g",
                  {
                    className: "nice-forecast-chart__annotation-marker",
                    onClick: () => I?.(n),
                    children: [
                      n.showLine !== !1 && /* @__PURE__ */ e(
                        "line",
                        {
                          className: "nice-forecast-chart__annotation-line",
                          x1: M,
                          x2: M,
                          y1: D.top,
                          y2: P.height - D.bottom,
                          stroke: n.color ?? "#9ca3af"
                        }
                      ),
                      /* @__PURE__ */ e("circle", { cx: M, cy: D.top + 10, r: 8, fill: n.color ?? "#9ca3af" }),
                      /* @__PURE__ */ e("text", { x: M, y: D.top + 14, textAnchor: "middle", fill: "white", fontSize: "10", children: n.icon ?? "!" })
                    ]
                  },
                  n.id
                );
              }),
              /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__axis-line",
                  x1: D.left,
                  x2: D.left,
                  y1: D.top,
                  y2: P.height - D.bottom
                }
              ),
              /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__axis-line",
                  x1: D.left,
                  x2: P.width - D.right,
                  y1: P.height - D.bottom,
                  y2: P.height - D.bottom
                }
              ),
              ce.map((n) => /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-label",
                  x: D.left - 8,
                  y: q(n) + 4,
                  textAnchor: "end",
                  children: l?.format ? l.format(n) : Me(n, R)
                },
                n
              )),
              oe.map((n) => /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-label",
                  x: F(n),
                  y: P.height - D.bottom + 16,
                  textAnchor: "middle",
                  children: C?.format ? C.format(n) : Ae(n, R)
                },
                n.getTime()
              )),
              l?.title && /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-title",
                  x: 15,
                  y: P.height / 2,
                  textAnchor: "middle",
                  transform: `rotate(-90, 15, ${P.height / 2})`,
                  children: l.title
                }
              )
            ]
          }
        ),
        Z && /* @__PURE__ */ k(
          "div",
          {
            className: "nice-forecast-chart__tooltip",
            style: { left: K.x, top: K.y },
            children: [
              /* @__PURE__ */ e("div", { className: "nice-forecast-chart__tooltip-date", children: Ae(Z.date, R) }),
              Z.values.map((n) => {
                const M = n.value ?? n.forecast;
                return M == null ? null : /* @__PURE__ */ k("div", { className: "nice-forecast-chart__tooltip-item", children: [
                  /* @__PURE__ */ e(
                    "span",
                    {
                      className: "nice-forecast-chart__tooltip-color",
                      style: { background: n.scenario.color }
                    }
                  ),
                  /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-label", children: n.scenario.name }),
                  /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-value", children: Me(M, R) })
                ] }, n.scenario.id);
              }),
              Z.values.some((n) => n.lowerBound != null) && /* @__PURE__ */ k("div", { className: "nice-forecast-chart__tooltip-confidence", children: [
                B.confidence ?? "CI",
                ":",
                " ",
                Me(Z.values[0]?.lowerBound ?? 0, R),
                " –",
                " ",
                Me(Z.values[0]?.upperBound ?? 0, R)
              ] })
            ]
          }
        )
      ] }),
      S.enabled && /* @__PURE__ */ e("div", { className: "nice-forecast-chart__legend", children: W.map((n) => /* @__PURE__ */ k(
        "div",
        {
          className: `nice-forecast-chart__legend-item ${n.visible === !1 ? "nice-forecast-chart__legend-item--hidden" : ""}`,
          onClick: () => E(n.id),
          children: [
            /* @__PURE__ */ e(
              "span",
              {
                className: `nice-forecast-chart__legend-color ${n.isBase ? "" : "nice-forecast-chart__legend-color--dashed"}`,
                style: { background: n.color }
              }
            ),
            n.name
          ]
        },
        n.id
      )) })
    ] });
  }
), Xe = ve(({
  data: t,
  renderNode: a,
  selectable: d,
  selectedKey: c,
  onSelect: r,
  direction: u = "top-down",
  collapsible: i = !0,
  className: m,
  style: C,
  id: l
}, v) => {
  const f = ke(l), [S, y] = ie(/* @__PURE__ */ new Set()), p = te((h) => {
    y((w) => {
      const b = new Set(w);
      return b.has(h) ? b.delete(h) : b.add(h), b;
    });
  }, []), o = te((h) => {
    d && r?.(h);
  }, [d, r]), s = te((h) => {
    const w = S.has(h.key), b = h.children && h.children.length > 0;
    return /* @__PURE__ */ k("li", { className: "nice-org-chart__item", children: [
      /* @__PURE__ */ k(
        "div",
        {
          className: `nice-org-chart__node${c === h.key ? " nice-org-chart__node--selected" : ""}`,
          onClick: () => o(h.key),
          role: d ? "button" : void 0,
          children: [
            a ? a(h) : /* @__PURE__ */ e("span", { children: h.label }),
            i && b && /* @__PURE__ */ e(
              "button",
              {
                type: "button",
                className: "nice-org-chart__toggle",
                onClick: (A) => {
                  A.stopPropagation(), p(h.key);
                },
                "aria-label": w ? "Expand" : "Collapse",
                children: w ? "+" : "−"
              }
            )
          ]
        }
      ),
      b && !w && /* @__PURE__ */ e("ul", { className: "nice-org-chart__children", children: h.children.map((A) => s(A)) })
    ] }, h.key);
  }, [S, c, a, d, i, o, p]);
  return /* @__PURE__ */ e(
    "div",
    {
      ref: v,
      id: f,
      className: `nice-org-chart nice-org-chart--${u} ${m || ""}`,
      style: C,
      children: /* @__PURE__ */ e("ul", { className: "nice-org-chart__root", children: s(t) })
    }
  );
});
Xe.displayName = "NiceOrganizationChart";
function Ze(t, a, d) {
  const c = (y) => {
    const p = y.replace("#", "");
    return [parseInt(p.slice(0, 2), 16), parseInt(p.slice(2, 4), 16), parseInt(p.slice(4, 6), 16)];
  }, [r, u, i] = c(t), [m, C, l] = c(a), v = Math.round(r + (m - r) * d), f = Math.round(u + (C - u) * d), S = Math.round(i + (l - i) * d);
  return `rgb(${v},${f},${S})`;
}
const Ge = ve(({
  data: t,
  xLabels: a,
  yLabels: d,
  colors: c = ["#e0f2fe", "#1d4ed8"],
  onCellClick: r,
  cellSize: u = 40,
  showValues: i = !0,
  className: m,
  style: C,
  id: l
}, v) => {
  const f = ke(l), { minVal: S, maxVal: y } = me(() => {
    let o = 1 / 0, s = -1 / 0;
    for (const h of t) for (const w of h)
      w < o && (o = w), w > s && (s = w);
    return { minVal: o, maxVal: s };
  }, [t]), p = te((o) => y === S ? 0.5 : (o - S) / (y - S), [S, y]);
  return /* @__PURE__ */ e("div", { ref: v, id: f, className: `nice-heatmap ${m || ""}`, style: C, children: /* @__PURE__ */ k("table", { className: "nice-heatmap__table", children: [
    a && /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ k("tr", { children: [
      d && /* @__PURE__ */ e("th", {}),
      a.map((o, s) => /* @__PURE__ */ e("th", { className: "nice-heatmap__header", children: o }, s))
    ] }) }),
    /* @__PURE__ */ e("tbody", { children: t.map((o, s) => /* @__PURE__ */ k("tr", { children: [
      d && /* @__PURE__ */ e("th", { className: "nice-heatmap__row-label", children: d[s] }),
      o.map((h, w) => /* @__PURE__ */ e(
        "td",
        {
          className: "nice-heatmap__cell",
          style: {
            background: Ze(c[0], c[1], p(h)),
            width: u,
            height: u,
            textAlign: "center",
            color: p(h) > 0.6 ? "#fff" : "#333",
            cursor: r ? "pointer" : void 0
          },
          onClick: () => r?.(s, w, h),
          title: String(h),
          children: i ? h : ""
        },
        w
      ))
    ] }, s)) })
  ] }) });
});
Ge.displayName = "NiceHeatMap";
function Ue(t, a) {
  const d = t.reduce((l, v) => l + v.value, 0);
  if (d === 0 || t.length === 0) return [];
  const c = [];
  let { x: r, y: u, w: i, h: m } = a;
  const C = [...t].sort((l, v) => v.value - l.value);
  for (const l of C) {
    const v = l.value / d;
    if (i >= m) {
      const f = i * v;
      c.push({ x: r, y: u, w: f, h: m, node: l }), r += f, i -= f;
    } else {
      const f = m * v;
      c.push({ x: r, y: u, w: i, h: f, node: l }), u += f, m -= f;
    }
  }
  return c;
}
const qe = ["#3b82f6", "#10b981", "#f59e0b", "#ef4444", "#8b5cf6", "#06b6d4", "#ec4899", "#84cc16"], Je = ve(({
  data: t,
  width: a = 600,
  height: d = 400,
  onNodeClick: c,
  colors: r = qe,
  className: u,
  style: i,
  id: m
}, C) => {
  const l = ke(m), v = me(() => {
    const f = t.children ?? [t];
    return Ue(f, { x: 0, y: 0, w: a, h: d });
  }, [t, a, d]);
  return /* @__PURE__ */ e("div", { ref: C, id: l, className: `nice-treemap ${u || ""}`, style: i, children: /* @__PURE__ */ e("svg", { width: a, height: d, className: "nice-treemap__svg", children: v.map((f, S) => /* @__PURE__ */ k("g", { onClick: () => c?.(f.node), style: { cursor: c ? "pointer" : void 0 }, children: [
    /* @__PURE__ */ e(
      "rect",
      {
        x: f.x,
        y: f.y,
        width: Math.max(f.w - 1, 0),
        height: Math.max(f.h - 1, 0),
        fill: f.node.color ?? r[S % r.length],
        rx: 2
      }
    ),
    f.w > 40 && f.h > 20 && /* @__PURE__ */ e(
      "text",
      {
        x: f.x + f.w / 2,
        y: f.y + f.h / 2,
        textAnchor: "middle",
        dominantBaseline: "central",
        fill: "#fff",
        fontSize: Math.min(12, f.w / 6),
        className: "nice-treemap__label",
        children: f.node.label
      }
    )
  ] }, f.node.key)) }) });
});
Je.displayName = "NiceTreeMap";
const Qe = ve(({
  data: t,
  type: a = "candlestick",
  showVolume: d = !0,
  width: c = 800,
  height: r = 400,
  bullColor: u = "#22c55e",
  bearColor: i = "#ef4444",
  className: m,
  style: C,
  id: l
}, v) => {
  const f = ke(l), S = { top: 20, right: 20, bottom: d ? 80 : 30, left: 60 }, y = c - S.left - S.right, p = d ? 50 : 0, o = r - S.top - S.bottom - p, { minP: s, maxP: h, maxVol: w } = me(() => {
    let g = 1 / 0, T = -1 / 0, x = 0;
    for (const O of t)
      O.low < g && (g = O.low), O.high > T && (T = O.high), O.volume && O.volume > x && (x = O.volume);
    return { minP: g, maxP: T, maxVol: x };
  }, [t]), b = Math.max(1, y / t.length * 0.7), A = (g) => S.left + (g + 0.5) * (y / t.length), N = (g) => S.top + o - (g - s) / (h - s || 1) * o, I = (g) => r - S.bottom - p + p * (1 - g / (w || 1));
  return /* @__PURE__ */ e("div", { ref: v, id: f, className: `nice-stock-chart ${m || ""}`, style: C, children: /* @__PURE__ */ k("svg", { width: c, height: r, className: "nice-stock-chart__svg", children: [
    [0, 0.25, 0.5, 0.75, 1].map((g) => {
      const T = s + g * (h - s);
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e(
          "line",
          {
            x1: S.left,
            x2: c - S.right,
            y1: N(T),
            y2: N(T),
            stroke: "#e5e7eb",
            strokeDasharray: "2,2"
          }
        ),
        /* @__PURE__ */ e("text", { x: S.left - 4, y: N(T) + 4, textAnchor: "end", fontSize: 10, fill: "#888", children: T.toFixed(2) })
      ] }, g);
    }),
    a === "line" ? /* @__PURE__ */ e(
      "polyline",
      {
        points: t.map((g, T) => `${A(T)},${N(g.close)}`).join(" "),
        fill: "none",
        stroke: u,
        strokeWidth: 1.5
      }
    ) : t.map((g, T) => {
      const x = g.close >= g.open, O = x ? u : i, B = A(T);
      if (a === "ohlc")
        return /* @__PURE__ */ k("g", { children: [
          /* @__PURE__ */ e("line", { x1: B, x2: B, y1: N(g.high), y2: N(g.low), stroke: O, strokeWidth: 1 }),
          /* @__PURE__ */ e("line", { x1: B - b / 2, x2: B, y1: N(g.open), y2: N(g.open), stroke: O, strokeWidth: 1.5 }),
          /* @__PURE__ */ e("line", { x1: B, x2: B + b / 2, y1: N(g.close), y2: N(g.close), stroke: O, strokeWidth: 1.5 })
        ] }, T);
      const R = N(Math.max(g.open, g.close)), G = N(Math.min(g.open, g.close));
      return /* @__PURE__ */ k("g", { children: [
        /* @__PURE__ */ e("line", { x1: B, x2: B, y1: N(g.high), y2: N(g.low), stroke: O, strokeWidth: 1 }),
        /* @__PURE__ */ e(
          "rect",
          {
            x: B - b / 2,
            y: R,
            width: b,
            height: Math.max(G - R, 1),
            fill: x ? "transparent" : O,
            stroke: O,
            strokeWidth: 1
          }
        )
      ] }, T);
    }),
    d && t.map((g, T) => {
      if (!g.volume) return null;
      const x = g.close >= g.open;
      return /* @__PURE__ */ e(
        "rect",
        {
          x: A(T) - b / 2,
          y: I(g.volume),
          width: b,
          height: r - S.bottom - I(g.volume),
          fill: x ? u : i,
          opacity: 0.3
        },
        `v${T}`
      );
    }),
    t.map((g, T) => T % Math.max(1, Math.floor(t.length / 8)) !== 0 ? null : /* @__PURE__ */ e(
      "text",
      {
        x: A(T),
        y: r - S.bottom + p + 14,
        textAnchor: "middle",
        fontSize: 9,
        fill: "#888",
        children: g.date
      },
      `l${T}`
    ))
  ] }) });
});
Qe.displayName = "NiceStockChart";
export {
  fe as C,
  ft as N,
  mt as a,
  De as b,
  ct as c,
  ht as d,
  _t as e,
  pt as f,
  Ge as g,
  dt as h,
  Fe as i,
  Xe as j,
  it as k,
  lt as l,
  xt as m,
  Ee as n,
  ut as o,
  Qe as p,
  Je as q,
  Ye as r,
  st as s,
  at as t,
  ot as u,
  rt as v,
  gt as w,
  yt as x
};
