import { jsx as e, jsxs as $, Fragment as Te } from "react/jsx-runtime";
import { useRef as be, useState as ce, useMemo as fe, useCallback as te, forwardRef as _e, useEffect as Ne, useImperativeHandle as ze } from "react";
import { b as Pe, u as Re, a5 as We, y as $e } from "./index-BQJzPBop.js";
const ke = ["#3b82f6", "#ef4444", "#22c55e", "#f59e0b", "#8b5cf6", "#ec4899", "#06b6d4", "#84cc16"], De = ({
  series: t,
  categories: h,
  width: o = 600,
  height: i = 400,
  title: n,
  showLegend: p = !0,
  showGrid: f = !0,
  yAxisLabel: A,
  xAxisLabel: w,
  stacked: x,
  zoomable: N,
  crosshair: g,
  annotations: y,
  legendInteractive: v,
  onDataPointClick: b,
  exportable: r,
  className: d,
  style: l
}) => {
  var xe, ye;
  const S = be(null), [_, C] = ce(/* @__PURE__ */ new Set()), [u, L] = ce(null), [s, R] = ce(null), [c, W] = ce(!1), z = be(null), Y = fe(
    () => t.filter((k) => !_.has(k.name)),
    [t, _]
  ), U = te((k) => {
    v && C((H) => {
      const F = new Set(H);
      return F.has(k) ? F.delete(k) : F.add(k), F;
    });
  }, [v]), B = { top: n ? 40 : 20, right: 20, bottom: w ? 60 : 40, left: A ? 60 : 50 }, Z = o - B.left - B.right, V = i - B.top - B.bottom, J = ((xe = Y[0]) == null ? void 0 : xe.data.length) ?? ((ye = t[0]) == null ? void 0 : ye.data.length) ?? 0, E = (s == null ? void 0 : s.start) ?? 0, oe = (s == null ? void 0 : s.end) ?? J, K = oe - E, ae = fe(
    () => Y.map((k) => ({ ...k, data: k.data.slice(E, oe) })),
    [Y, E, oe]
  ), I = fe(
    () => h == null ? void 0 : h.slice(E, oe),
    [h, E, oe]
  ), { minY: j, maxY: re, yTicks: G } = fe(() => {
    let k;
    if (x) {
      k = [];
      for (let P = 0; P < K; P++)
        k.push(ae.reduce((ie, de) => ie + (de.data[P] || 0), 0));
    } else
      k = ae.flatMap((P) => P.data);
    k.length === 0 && (k = [0]);
    const H = Math.min(0, ...k), F = Math.max(0, ...k), ne = F - H || 1, a = Math.pow(10, Math.floor(Math.log10(ne))) || 1, M = Math.floor(H / a) * a, D = Math.ceil(F / a) * a, m = [];
    for (let P = M; P <= D; P += a) m.push(Math.round(P * 1e6) / 1e6);
    return m.length < 2 && m.push(D), { minY: M, maxY: D, yTicks: m };
  }, [ae, K, x]), X = (k) => V - (k - j) / (re - j || 1) * V, Q = (k) => (k + 0.5) / K * Z, pe = K > 0 ? Z / K / (x ? 1.5 : Math.max(Y.length, 1) * 1.5) : 20, ve = te((k) => {
    if (!N) return;
    k.preventDefault();
    const H = s ?? { start: 0, end: J }, F = H.end - H.start, ne = (H.start + H.end) / 2, a = k.deltaY > 0 ? 1.2 : 0.8, M = Math.max(2, Math.min(J, Math.round(F * a))), D = Math.max(0, Math.round(ne - M / 2)), m = Math.min(J, D + M);
    R({ start: D, end: m });
  }, [N, s, J]), ue = te((k) => {
    N && (W(!0), z.current = { x: k.clientX, range: s ?? { start: 0, end: J } });
  }, [N, s, J]), T = te((k) => {
    var F;
    const H = (F = S.current) == null ? void 0 : F.getBoundingClientRect();
    if (H && L({ x: k.clientX - H.left - B.left, y: k.clientY - H.top - B.top }), c && z.current && N) {
      const ne = k.clientX - z.current.x, a = Z / K, M = -Math.round(ne / a), D = z.current.range, m = D.end - D.start;
      let P = D.start + M;
      P < 0 && (P = 0), P + m > J && (P = J - m), R({ start: P, end: P + m });
    }
  }, [c, N, Z, K, J, B.left, B.top]), O = te(() => {
    W(!1), z.current = null;
  }, []), q = te(() => {
    L(null), W(!1), z.current = null;
  }, []), ge = te(() => {
    const k = S.current;
    if (!k) return;
    const H = new XMLSerializer().serializeToString(k), F = document.createElement("canvas");
    F.width = o, F.height = i + (p ? 30 : 0);
    const ne = F.getContext("2d");
    if (!ne) return;
    const a = new Image();
    a.onload = () => {
      ne.fillStyle = "#fff", ne.fillRect(0, 0, F.width, F.height), ne.drawImage(a, 0, 0);
      const M = document.createElement("a");
      M.download = "chart.png", M.href = F.toDataURL("image/png"), M.click();
    }, a.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(H);
  }, [o, i, p]);
  return /* @__PURE__ */ $("div", { className: `nice-chart ${d || ""}`, style: l, children: [
    r && /* @__PURE__ */ e("button", { type: "button", className: "nice-chart__export-btn", onClick: ge, title: "Export PNG", children: "📷" }),
    /* @__PURE__ */ $(
      "svg",
      {
        ref: S,
        width: o,
        height: i + (p ? 30 : 0),
        className: "nice-chart__svg",
        onWheel: ve,
        onMouseDown: ue,
        onMouseMove: T,
        onMouseUp: O,
        onMouseLeave: q,
        children: [
          /* @__PURE__ */ $("g", { transform: `translate(${B.left},${B.top})`, children: [
            n && /* @__PURE__ */ e("text", { x: Z / 2, y: -10, textAnchor: "middle", className: "nice-chart__title", children: n }),
            f && G.map((k) => /* @__PURE__ */ $("g", { children: [
              /* @__PURE__ */ e("line", { x1: 0, y1: X(k), x2: Z, y2: X(k), className: "nice-chart__grid-line" }),
              /* @__PURE__ */ e("text", { x: -8, y: X(k) + 4, textAnchor: "end", className: "nice-chart__axis-label", children: k })
            ] }, k)),
            I && I.map((k, H) => /* @__PURE__ */ e("text", { x: Q(H), y: V + 20, textAnchor: "middle", className: "nice-chart__axis-label", children: k }, H)),
            A && /* @__PURE__ */ e("text", { x: -B.left + 14, y: V / 2, textAnchor: "middle", transform: `rotate(-90, -${B.left - 14}, ${V / 2})`, className: "nice-chart__axis-title", children: A }),
            w && /* @__PURE__ */ e("text", { x: Z / 2, y: V + 45, textAnchor: "middle", className: "nice-chart__axis-title", children: w }),
            /* @__PURE__ */ e("line", { x1: 0, y1: 0, x2: 0, y2: V, className: "nice-chart__axis" }),
            /* @__PURE__ */ e("line", { x1: 0, y1: V, x2: Z, y2: V, className: "nice-chart__axis" }),
            y == null ? void 0 : y.map((k, H) => {
              if (k.type === "line") {
                const F = X(k.value);
                return /* @__PURE__ */ $("g", { children: [
                  /* @__PURE__ */ e("line", { x1: 0, y1: F, x2: Z, y2: F, stroke: k.color || "#ef4444", strokeWidth: 1.5, strokeDasharray: k.dash || "6,3" }),
                  k.label && /* @__PURE__ */ e("text", { x: Z + 4, y: F + 4, className: "nice-chart__annotation-label", fill: k.color || "#ef4444", children: k.label })
                ] }, H);
              }
              return /* @__PURE__ */ e("text", { x: Q(k.value), y: -4, textAnchor: "middle", className: "nice-chart__annotation-label", fill: k.color || "#6b7280", children: k.label }, H);
            }),
            g && u && u.x >= 0 && u.x <= Z && u.y >= 0 && u.y <= V && /* @__PURE__ */ $(Te, { children: [
              /* @__PURE__ */ e("line", { x1: u.x, y1: 0, x2: u.x, y2: V, stroke: "#9ca3af", strokeWidth: 1, strokeDasharray: "4,2" }),
              /* @__PURE__ */ e("line", { x1: 0, y1: u.y, x2: Z, y2: u.y, stroke: "#9ca3af", strokeWidth: 1, strokeDasharray: "4,2" })
            ] }),
            ae.map((k, H) => {
              const F = k.color || ke[H % ke.length], ne = k.type || "bar";
              if (ne === "bar")
                return /* @__PURE__ */ e("g", { children: k.data.map((M, D) => {
                  let m, P;
                  if (x) {
                    const de = ae.slice(0, H).reduce((se, le) => se + (le.data[D] || 0), 0);
                    m = X(de + M), P = X(de) - m;
                  } else
                    m = X(Math.max(0, M)), P = Math.abs(X(M) - X(0));
                  const ie = x ? Q(D) - pe / 2 : Q(D) - ae.length * pe / 2 + H * pe;
                  return /* @__PURE__ */ e(
                    "rect",
                    {
                      x: ie,
                      y: m,
                      width: pe * 0.9,
                      height: Math.max(0, P),
                      fill: F,
                      rx: 2,
                      style: b ? { cursor: "pointer" } : void 0,
                      onClick: b ? () => b(k.name, E + D, M) : void 0,
                      children: /* @__PURE__ */ e("title", { children: `${k.name}: ${M}` })
                    },
                    D
                  );
                }) }, k.name);
              const a = k.data.map((M, D) => `${Q(D)},${X(M)}`);
              return /* @__PURE__ */ $("g", { children: [
                ne === "area" && /* @__PURE__ */ e(
                  "polygon",
                  {
                    points: `${Q(0)},${X(0)} ${a.join(" ")} ${Q(K - 1)},${X(0)}`,
                    fill: F,
                    opacity: 0.15
                  }
                ),
                /* @__PURE__ */ e("polyline", { points: a.join(" "), fill: "none", stroke: F, strokeWidth: 2 }),
                k.data.map((M, D) => /* @__PURE__ */ e(
                  "circle",
                  {
                    cx: Q(D),
                    cy: X(M),
                    r: 3,
                    fill: F,
                    style: b ? { cursor: "pointer" } : void 0,
                    onClick: b ? () => b(k.name, E + D, M) : void 0,
                    children: /* @__PURE__ */ e("title", { children: `${k.name}: ${M}` })
                  },
                  D
                ))
              ] }, k.name);
            })
          ] }),
          p && /* @__PURE__ */ e("g", { transform: `translate(${B.left}, ${i})`, children: t.map((k, H) => {
            const F = H * 120, ne = _.has(k.name);
            return /* @__PURE__ */ $(
              "g",
              {
                transform: `translate(${F}, 10)`,
                style: v ? { cursor: "pointer" } : void 0,
                onClick: () => U(k.name),
                opacity: ne ? 0.35 : 1,
                children: [
                  /* @__PURE__ */ e("rect", { width: 12, height: 12, rx: 2, fill: k.color || ke[H % ke.length] }),
                  /* @__PURE__ */ e(
                    "text",
                    {
                      x: 16,
                      y: 10,
                      className: "nice-chart__legend-text",
                      style: ne ? { textDecoration: "line-through" } : void 0,
                      children: k.name
                    }
                  )
                ]
              },
              k.name
            );
          }) })
        ]
      }
    )
  ] });
}, at = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceChart: De
}, Symbol.toStringTag, { value: "Module" }));
function je(t) {
  if (!t.length)
    return { categories: [], numericFields: [], sampleValues: {} };
  const h = t[0], o = [], i = {};
  let n = null;
  for (const [p, f] of Object.entries(h))
    typeof f == "number" ? (o.push(p), i[p] = t.map((A) => Number(A[p]) || 0)) : !n && (typeof f == "string" || f instanceof Date) && (n = p);
  return { categories: n ? t.map((p) => String(p[n] || "")) : t.map((p, f) => `Item ${f + 1}`), numericFields: o, sampleValues: i };
}
function Ye(t, h) {
  const { categories: o, numericFields: i, sampleValues: n } = je(t);
  return { series: i.map((p, f) => ({
    name: p.replace(/([A-Z])/g, " $1").replace(/^./, (A) => A.toUpperCase()).trim(),
    data: n[p],
    type: h === "area" ? "area" : h === "line" ? "line" : "bar"
  })), categories: o };
}
_e(function(t, h) {
  const {
    rawData: o,
    enableAI: i = !0,
    aiModel: n,
    enableAutoType: p = !0,
    enableInsights: f = !0,
    dataDescription: A,
    onChartSuggestion: w,
    onInsights: x,
    showAIToolbar: N = !0,
    showInsightsOnLoad: g = !1,
    series: y,
    categories: v,
    ...b
  } = t, [r, d] = ce("bar"), [l, S] = ce(null), [_, C] = ce([]), [u, L] = ce(g), [s, R] = ce(null), { t: c } = Pe(), W = Re(), { suggestChartType: z, generateInsights: Y, isLoading: U } = We(), B = i && W.isConfigured, { series: Z, categories: V } = o ? Ye(o, s || r) : { series: y || [], categories: v }, J = te(async () => {
    if (!B || !p)
      return { type: "bar", reason: "Default", config: {} };
    const I = o || (y != null && y.length ? y.flatMap((j) => j.data.map((re, G) => ({ [j.name]: re, index: G }))) : []);
    try {
      const j = await z(I, A), re = {
        type: j.type,
        reason: j.reason,
        config: j.config
      };
      return S(re), d(re.type), w == null || w(re), re;
    } catch {
      return { type: "bar", reason: "Default fallback", config: {} };
    }
  }, [B, p, o, y, A, z, w]), E = te(async () => {
    if (!B || !f) return [];
    const I = o || (y != null && y.length ? y.flatMap((j) => j.data.map((re, G) => ({ [j.name]: re, category: (v == null ? void 0 : v[G]) || G }))) : []);
    try {
      const j = await Y(I, s || r);
      return C(j), x == null || x(j), j;
    } catch {
      return [];
    }
  }, [B, f, o, y, v, r, s, Y, x]), oe = te(() => s || r, [s, r]);
  Ne(() => {
    B && p && (o != null && o.length || y != null && y.length) && J();
  }, [B, p, o, y]), ze(h, () => ({
    getSuggestion: J,
    generateInsights: E,
    getCurrentType: oe
  }));
  const K = [
    { 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" }
  ], ae = s || r;
  return /* @__PURE__ */ $("div", { className: "nice-chart-ai", "data-testid": t["data-testid"], children: [
    N && B && /* @__PURE__ */ $("div", { className: "nice-chart-ai__toolbar", children: [
      /* @__PURE__ */ $("div", { className: "nice-chart-ai__toolbar-left", children: [
        /* @__PURE__ */ e("span", { className: "nice-chart-ai__badge", children: "AI" }),
        l && /* @__PURE__ */ $("div", { className: "nice-chart-ai__suggestion", children: [
          /* @__PURE__ */ e("span", { className: "nice-chart-ai__suggestion-icon", children: "💡" }),
          /* @__PURE__ */ $("span", { className: "nice-chart-ai__suggestion-text", children: [
            c("chartAI.suggestedType", "Suggested:"),
            " ",
            l.type
          ] }),
          /* @__PURE__ */ $("span", { className: "nice-chart-ai__suggestion-reason", title: l.reason, children: [
            "(",
            l.reason,
            ")"
          ] })
        ] }),
        U && /* @__PURE__ */ e("span", { className: "nice-chart-ai__loading", children: c("chartAI.analyzing", "Analyzing...") })
      ] }),
      /* @__PURE__ */ e("div", { className: "nice-chart-ai__toolbar-center", children: /* @__PURE__ */ e("div", { className: "nice-chart-ai__type-selector", children: K.filter((I) => ["bar", "line", "area"].includes(I.type)).map(({ type: I, icon: j, label: re }) => /* @__PURE__ */ e(
        "button",
        {
          type: "button",
          className: `nice-chart-ai__type-btn ${ae === I ? "nice-chart-ai__type-btn--active" : ""}`,
          onClick: () => R(I),
          title: re,
          children: j
        },
        I
      )) }) }),
      /* @__PURE__ */ $("div", { className: "nice-chart-ai__toolbar-right", children: [
        /* @__PURE__ */ $(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__auto-btn",
            onClick: () => J(),
            disabled: U,
            title: c("chartAI.autoDetect", "Auto-detect best chart type"),
            children: [
              "🔮 ",
              c("chartAI.auto", "Auto")
            ]
          }
        ),
        f && /* @__PURE__ */ $(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__insights-btn",
            onClick: () => {
              _.length || E(), L(!u);
            },
            disabled: U,
            title: c("chartAI.showInsights", "Show data insights"),
            children: [
              "💡 ",
              c("chartAI.insights", "Insights")
            ]
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("div", { className: "nice-chart-ai__chart-wrapper", children: /* @__PURE__ */ e(
      De,
      {
        series: Z,
        categories: V,
        ...b
      }
    ) }),
    u && _.length > 0 && /* @__PURE__ */ $("div", { className: "nice-chart-ai__insights", children: [
      /* @__PURE__ */ $("div", { className: "nice-chart-ai__insights-header", children: [
        /* @__PURE__ */ $("h4", { children: [
          "💡 ",
          c("chartAI.dataInsights", "Data Insights")
        ] }),
        /* @__PURE__ */ e(
          "button",
          {
            type: "button",
            className: "nice-chart-ai__insights-close",
            onClick: () => L(!1),
            children: "✕"
          }
        )
      ] }),
      /* @__PURE__ */ e("ul", { className: "nice-chart-ai__insights-list", children: _.map((I, j) => /* @__PURE__ */ $("li", { className: "nice-chart-ai__insight", children: [
        /* @__PURE__ */ e("span", { className: "nice-chart-ai__insight-icon", children: "•" }),
        I
      ] }, j)) }),
      /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights-footer", children: /* @__PURE__ */ $(
        "button",
        {
          type: "button",
          className: "nice-chart-ai__refresh",
          onClick: () => E(),
          disabled: U,
          children: [
            "🔄 ",
            c("chartAI.refresh", "Refresh")
          ]
        }
      ) })
    ] }),
    u && U && /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights nice-chart-ai__insights--loading", children: /* @__PURE__ */ $("div", { className: "nice-chart-ai__loading-content", children: [
      /* @__PURE__ */ e("span", { className: "nice-chart-ai__spinner" }),
      c("chartAI.generatingInsights", "Generating insights...")
    ] }) })
  ] });
});
function Oe(t, h) {
  const o = t ? typeof t == "number" ? new Date(t) : new Date(t) : /* @__PURE__ */ new Date(), i = (w) => w.toString().padStart(2, "0"), n = i(o.getHours()), p = i(o.getMinutes()), f = i(o.getSeconds()), A = o.getMilliseconds().toString().padStart(3, "0");
  switch (h) {
    case "HH:mm:ss":
      return `${n}:${p}:${f}`;
    case "HH:mm":
      return `${n}:${p}`;
    case "mm:ss":
      return `${p}:${f}`;
    case "ss.SSS":
      return `${f}.${A}`;
    case "ISO":
      return o.toISOString();
    default:
      return `${n}:${p}:${f}`;
  }
}
function Le(t) {
  if (t.length === 0) return null;
  const h = Math.min(...t), o = Math.max(...t), i = t.reduce((p, f) => p + f, 0) / t.length, n = t[t.length - 1];
  return { min: h, max: o, avg: i, current: n, count: t.length };
}
const Fe = _e(
  ({
    series: t,
    maxPoints: h = 100,
    slidingWindow: o = !0,
    refreshRate: i = 16,
    dataSource: n,
    width: p = 600,
    height: f = 400,
    title: A,
    showLegend: w = !0,
    showGrid: x = !0,
    yAxisLabel: N,
    xAxisLabel: g,
    stacked: y,
    zoomable: v,
    crosshair: b,
    annotations: r = [],
    legendInteractive: d,
    onDataPointClick: l,
    exportable: S,
    showControls: _ = !0,
    showStatus: C = !0,
    initialPaused: u = !1,
    onDataReceived: L,
    onDataDropped: s,
    timeFormat: R = "HH:mm:ss",
    showStats: c,
    thresholds: W = [],
    className: z,
    style: Y
  }, U) => {
    const [B, Z] = ce(() => {
      var O;
      const T = /* @__PURE__ */ new Map();
      for (const q of t)
        T.set(q.name, ((O = q.initialData) == null ? void 0 : O.slice()) ?? []);
      return T;
    }), [V, J] = ce([]), [E, oe] = ce(u), [K, ae] = ce(!1), I = be([]), j = be(Date.now()), re = be(null), G = te(() => {
      const T = I.current;
      T.length !== 0 && (I.current = [], Z((O) => {
        const q = new Map(O);
        for (const ge of T) {
          const xe = q.get(ge.series);
          if (!xe) continue;
          const ye = [...xe, ge.value];
          if (o && ye.length > h) {
            const k = ye.length - h;
            s == null || s(k, ge.series), ye.splice(0, k);
          }
          q.set(ge.series, ye);
        }
        return q;
      }), T.length > 0 && J((O) => {
        const q = [...O];
        for (const ge of T) {
          const xe = ge.category ?? Oe(ge.timestamp, R);
          q.push(xe);
        }
        return o && q.length > h && q.splice(0, q.length - h), q;
      }));
    }, [o, h, R, s]), X = te(() => {
      const T = Date.now();
      T - j.current >= i && (G(), j.current = T), re.current = requestAnimationFrame(X);
    }, [i, G]);
    Ne(() => (E || (re.current = requestAnimationFrame(X)), () => {
      re.current !== null && (cancelAnimationFrame(re.current), re.current = null);
    }), [E, X]);
    const Q = te(
      (T) => {
        if (E) return;
        const O = "points" in T ? T.points : [T];
        for (const q of O)
          B.has(q.series) && (I.current.push(q), L == null || L(q));
      },
      [E, B, L]
    );
    Ne(() => {
      if (!n) return;
      const T = n.subscribe(Q);
      let O;
      return n.onStatusChange ? O = n.onStatusChange(ae) : ae(!0), n.fetchHistory && n.fetchHistory(h).then((q) => {
        for (const ge of q)
          I.current.push(ge);
        G();
      }), () => {
        T(), O == null || O();
      };
    }, [n, Q, h, G]);
    const pe = fe(() => t.map((T) => ({
      name: T.name,
      color: T.color,
      type: T.type,
      data: B.get(T.name) ?? []
    })), [t, B]), ve = fe(() => {
      const T = [...r];
      for (const O of W)
        T.push({
          type: "line",
          value: O.value,
          color: O.color,
          label: O.label,
          dash: O.style === "dashed" ? "5,5" : O.style === "dotted" ? "2,2" : void 0
        });
      return T;
    }, [r, W]);
    ze(
      U,
      () => ({
        pause() {
          oe(!0);
        },
        resume() {
          oe(!1);
        },
        isPaused() {
          return E;
        },
        clear() {
          Z((T) => {
            const O = new Map(T);
            for (const q of O.keys())
              O.set(q, []);
            return O;
          }), J([]), I.current = [];
        },
        addPoint(T) {
          Q(T);
        },
        addPoints(T) {
          Q({ points: T });
        },
        getData(T) {
          return B.get(T) ?? [];
        },
        getCategories() {
          return V;
        },
        exportData() {
          return { series: pe, categories: V };
        },
        getStats(T) {
          const O = B.get(T);
          return O ? Le(O) : null;
        }
      }),
      [E, B, V, pe, Q]
    );
    const ue = fe(() => {
      if (!c) return null;
      const T = {};
      for (const [O, q] of B)
        T[O] = Le(q);
      return T;
    }, [c, B]);
    return /* @__PURE__ */ $("div", { className: z, style: { position: "relative", ...Y }, children: [
      C && /* @__PURE__ */ $(
        "div",
        {
          style: {
            position: "absolute",
            top: 8,
            right: 8,
            display: "flex",
            alignItems: "center",
            gap: 4,
            fontSize: 12,
            color: K ? "#22c55e" : "#ef4444",
            zIndex: 10
          },
          children: [
            /* @__PURE__ */ e(
              "span",
              {
                style: {
                  width: 8,
                  height: 8,
                  borderRadius: "50%",
                  backgroundColor: K ? "#22c55e" : "#ef4444"
                }
              }
            ),
            K ? "Live" : "Disconnected"
          ]
        }
      ),
      _ && /* @__PURE__ */ e(
        "div",
        {
          style: {
            position: "absolute",
            top: 8,
            left: 8,
            display: "flex",
            gap: 4,
            zIndex: 10
          },
          children: /* @__PURE__ */ e(
            "button",
            {
              onClick: () => oe((T) => !T),
              style: {
                padding: "4px 8px",
                fontSize: 12,
                border: "1px solid #ddd",
                borderRadius: 4,
                background: E ? "#fef3c7" : "#fff",
                cursor: "pointer"
              },
              title: E ? "Resume" : "Pause",
              children: E ? "▶" : "⏸"
            }
          )
        }
      ),
      c && ue && /* @__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(ue).map(
            ([T, O]) => O ? /* @__PURE__ */ $("div", { style: { marginBottom: 4 }, children: [
              /* @__PURE__ */ e("strong", { children: T }),
              /* @__PURE__ */ $("div", { children: [
                "Min: ",
                O.min.toFixed(2),
                " | Max: ",
                O.max.toFixed(2)
              ] }),
              /* @__PURE__ */ $("div", { children: [
                "Avg: ",
                O.avg.toFixed(2),
                " | Now: ",
                O.current.toFixed(2)
              ] })
            ] }, T) : null
          )
        }
      ),
      /* @__PURE__ */ e(
        De,
        {
          series: pe,
          categories: V,
          width: p,
          height: f,
          title: A,
          showLegend: w,
          showGrid: x,
          yAxisLabel: N,
          xAxisLabel: g,
          stacked: y,
          zoomable: v,
          crosshair: b,
          annotations: ve,
          legendInteractive: d,
          onDataPointClick: l,
          exportable: S
        }
      )
    ] });
  }
);
Fe.displayName = "NiceLiveChart";
const me = ["#3b82f6", "#ef4444", "#22c55e", "#f59e0b", "#8b5cf6", "#ec4899", "#06b6d4", "#84cc16"], rt = ({
  data: t,
  width: h = 400,
  height: o = 400,
  innerRadius: i = 0,
  title: n,
  showLegend: p = !0,
  showLabels: f = !0,
  className: A,
  style: w
}) => {
  const x = h / 2, N = (o - (p ? 30 : 0)) / 2 + (n ? 10 : 0), g = Math.min(x, N) - 40, y = t.reduce((r, d) => r + d.value, 0);
  let v = -Math.PI / 2;
  const b = t.map((r, d) => {
    const l = r.value / (y || 1) * Math.PI * 2, S = v;
    v += l;
    const _ = v, C = (S + _) / 2, u = x + g * Math.cos(S), L = N + g * Math.sin(S), s = x + g * Math.cos(_), R = N + g * Math.sin(_), c = l > Math.PI ? 1 : 0, W = r.color || me[d % me.length];
    let z;
    if (i > 0) {
      const Z = x + i * Math.cos(S), V = N + i * Math.sin(S), J = x + i * Math.cos(_), E = N + i * Math.sin(_);
      z = `M${u},${L} A${g},${g} 0 ${c},1 ${s},${R} L${J},${E} A${i},${i} 0 ${c},0 ${Z},${V} Z`;
    } else
      z = `M${x},${N} L${u},${L} A${g},${g} 0 ${c},1 ${s},${R} Z`;
    const Y = x + g * 0.7 * Math.cos(C), U = N + g * 0.7 * Math.sin(C), B = y > 0 ? Math.round(r.value / y * 100) : 0;
    return { ...r, path: z, labelX: Y, labelY: U, pct: B, color: W };
  });
  return /* @__PURE__ */ e("div", { className: `nice-piechart ${A || ""}`, style: w, children: /* @__PURE__ */ $("svg", { width: h, height: o, className: "nice-piechart__svg", children: [
    n && /* @__PURE__ */ e("text", { x, y: 20, textAnchor: "middle", className: "nice-chart__title", children: n }),
    b.map((r, d) => /* @__PURE__ */ $("g", { children: [
      /* @__PURE__ */ e("path", { d: r.path, fill: r.color, stroke: "var(--bg-primary, #fff)", strokeWidth: 2, children: /* @__PURE__ */ e("title", { children: `${r.label}: ${r.value} (${r.pct}%)` }) }),
      f && r.pct >= 5 && /* @__PURE__ */ $("text", { x: r.labelX, y: r.labelY, textAnchor: "middle", dominantBaseline: "middle", className: "nice-piechart__label", children: [
        r.pct,
        "%"
      ] })
    ] }, d)),
    p && /* @__PURE__ */ e("g", { transform: `translate(10, ${o - 25})`, children: t.map((r, d) => /* @__PURE__ */ $("g", { transform: `translate(${d * 100}, 0)`, children: [
      /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: r.color || me[d % me.length] }),
      /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: r.label })
    ] }, d)) })
  ] }) });
}, nt = ({
  series: t,
  categories: h,
  width: o = 400,
  height: i = 400,
  maxValue: n,
  title: p,
  showLegend: f = !0,
  className: A,
  style: w
}) => {
  const x = o / 2, N = (i - (f ? 30 : 0)) / 2 + (p ? 10 : 0), g = Math.min(x, N) - 40, y = h.length, v = n ?? Math.max(...t.flatMap((l) => l.data), 1), b = Math.PI * 2 / y, r = 5, d = (l, S) => {
    const _ = l * b - Math.PI / 2, C = S / v * g;
    return { x: x + C * Math.cos(_), y: N + C * Math.sin(_) };
  };
  return /* @__PURE__ */ e("div", { className: `nice-polarchart ${A || ""}`, style: w, children: /* @__PURE__ */ $("svg", { width: o, height: i, className: "nice-polarchart__svg", children: [
    p && /* @__PURE__ */ e("text", { x, y: 20, textAnchor: "middle", className: "nice-chart__title", children: p }),
    Array.from({ length: r }, (l, S) => {
      const _ = g * ((S + 1) / r);
      return /* @__PURE__ */ e("circle", { cx: x, cy: N, r: _, fill: "none", stroke: "var(--border-color, #ddd)", strokeWidth: 0.5 }, S);
    }),
    h.map((l, S) => {
      const _ = d(S, v), C = d(S, v * 1.12);
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("line", { x1: x, y1: N, x2: _.x, y2: _.y, stroke: "var(--border-color, #ddd)", strokeWidth: 0.5 }),
        /* @__PURE__ */ e("text", { x: C.x, y: C.y, textAnchor: "middle", dominantBaseline: "middle", className: "nice-chart__axis-label", children: l })
      ] }, S);
    }),
    t.map((l, S) => {
      const _ = l.color || me[S % me.length], C = l.data.map((u, L) => {
        const s = d(L, u);
        return `${s.x},${s.y}`;
      }).join(" ");
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("polygon", { points: C, fill: l.fill !== !1 ? _ : "none", fillOpacity: 0.15, stroke: _, strokeWidth: 2 }),
        l.data.map((u, L) => {
          const s = d(L, u);
          return /* @__PURE__ */ e("circle", { cx: s.x, cy: s.y, r: 3, fill: _, children: /* @__PURE__ */ e("title", { children: `${l.name} - ${h[L]}: ${u}` }) }, L);
        })
      ] }, l.name);
    }),
    f && /* @__PURE__ */ e("g", { transform: `translate(10, ${i - 25})`, children: t.map((l, S) => /* @__PURE__ */ $("g", { transform: `translate(${S * 100}, 0)`, children: [
      /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: l.color || me[S % me.length] }),
      /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: l.name })
    ] }, S)) })
  ] }) });
}, it = ({
  value: t,
  min: h = 0,
  max: o = 100,
  width: i = 200,
  height: n = 200,
  startAngle: p = 225,
  endAngle: f = -45,
  color: A = "#3b82f6",
  trackColor: w,
  label: x,
  formatValue: N,
  ranges: g,
  className: y,
  style: v
}) => {
  const b = i / 2, r = n / 2, d = Math.min(b, r) - 20, l = Math.max(0, Math.min(1, (t - h) / (o - h || 1))), S = (c) => c * Math.PI / 180, _ = (p - f + 360) % 360 || 360, C = (c) => ({
    x: b + d * Math.cos(S(c)),
    y: r - d * Math.sin(S(c))
  }), u = (c, W) => {
    const z = C(c), Y = C(W), U = (c - W + 360) % 360 > 180 ? 1 : 0;
    return `M${z.x},${z.y} A${d},${d} 0 ${U},1 ${Y.x},${Y.y}`;
  }, L = p - l * _, s = C(L);
  let R = A;
  if (g) {
    for (const c of g)
      if (t >= c.start && t <= c.end) {
        R = c.color;
        break;
      }
  }
  return /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--circular ${y || ""}`, style: v, children: /* @__PURE__ */ $("svg", { width: i, height: n, children: [
    /* @__PURE__ */ e("path", { d: u(p, f), fill: "none", stroke: w || "var(--border-color, #e2e8f0)", strokeWidth: 12, strokeLinecap: "round" }),
    l > 0 && /* @__PURE__ */ e("path", { d: u(p, L), fill: "none", stroke: R, strokeWidth: 12, strokeLinecap: "round" }),
    /* @__PURE__ */ e("line", { x1: b, y1: r, x2: s.x, y2: s.y, stroke: "var(--text-primary, #333)", strokeWidth: 2, strokeLinecap: "round" }),
    /* @__PURE__ */ e("circle", { cx: b, cy: r, r: 4, fill: "var(--text-primary, #333)" }),
    /* @__PURE__ */ e("text", { x: b, y: r + d * 0.35, textAnchor: "middle", className: "nice-gauge__value", children: N ? N(t) : t }),
    x && /* @__PURE__ */ e("text", { x: b, y: r + d * 0.55, textAnchor: "middle", className: "nice-gauge__label", children: x })
  ] }) });
}, lt = ({
  value: t,
  min: h = 0,
  max: o = 100,
  width: i = 300,
  height: n = 60,
  orientation: p = "horizontal",
  color: f = "#3b82f6",
  label: A,
  formatValue: w,
  ranges: x,
  showTicks: N = !0,
  tickCount: g = 5,
  className: y,
  style: v
}) => {
  const b = p === "horizontal", r = b ? i - 40 : n - 40, d = Math.max(0, Math.min(1, (t - h) / (o - h || 1))), l = 10;
  let S = f;
  if (x) {
    for (const C of x)
      if (t >= C.start && t <= C.end) {
        S = C.color;
        break;
      }
  }
  const _ = Array.from({ length: g }, (C, u) => h + (o - h) * (u / (g - 1)));
  return b ? /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--linear ${y || ""}`, style: v, children: /* @__PURE__ */ $("svg", { width: i, height: n, children: [
    A && /* @__PURE__ */ e("text", { x: i / 2, y: 14, textAnchor: "middle", className: "nice-gauge__label", children: A }),
    /* @__PURE__ */ e("rect", { x: 20, y: n / 2 - l / 2, width: r, height: l, rx: 5, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: 20, y: n / 2 - l / 2, width: r * d, height: l, rx: 5, fill: S }),
    /* @__PURE__ */ e("polygon", { points: `${20 + r * d},${n / 2 - l / 2 - 2} ${20 + r * d - 5},${n / 2 - l / 2 - 10} ${20 + r * d + 5},${n / 2 - l / 2 - 10}`, fill: "var(--text-primary, #333)" }),
    /* @__PURE__ */ e("text", { x: 20 + r * d, y: n / 2 - l / 2 - 12, textAnchor: "middle", className: "nice-gauge__value", style: { fontSize: 11 }, children: w ? w(t) : t }),
    N && _.map((C, u) => {
      const L = 20 + (C - h) / (o - h) * r;
      return /* @__PURE__ */ e("text", { x: L, y: n / 2 + l / 2 + 14, textAnchor: "middle", className: "nice-gauge__tick", children: C }, u);
    })
  ] }) }) : /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--linear nice-gauge--vertical ${y || ""}`, style: v, children: /* @__PURE__ */ $("svg", { width: i, height: n, children: [
    /* @__PURE__ */ e("rect", { x: i / 2 - l / 2, y: 20, width: l, height: r, rx: 5, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: i / 2 - l / 2, y: 20 + r * (1 - d), width: l, height: r * d, rx: 5, fill: S }),
    /* @__PURE__ */ e("text", { x: i / 2, y: 14, textAnchor: "middle", className: "nice-gauge__value", children: w ? w(t) : t }),
    A && /* @__PURE__ */ e("text", { x: i / 2, y: n - 4, textAnchor: "middle", className: "nice-gauge__label", children: A })
  ] }) });
}, ot = ({
  items: t,
  min: h = 0,
  max: o = 100,
  width: i = 300,
  height: n = 300,
  startAngle: p = 225,
  endAngle: f = -45,
  formatValue: A,
  title: w,
  className: x,
  style: N
}) => {
  const g = i / 2, y = n / 2, v = Math.min(g, y) - 30, b = Math.min(20, v / (t.length + 1)), r = 4, d = (_) => _ * Math.PI / 180, l = (p - f + 360) % 360 || 360, S = (_, C, u) => {
    const L = g + _ * Math.cos(d(C)), s = y - _ * Math.sin(d(C)), R = g + _ * Math.cos(d(u)), c = y - _ * Math.sin(d(u)), W = (C - u + 360) % 360;
    return `M${L},${s} A${_},${_} 0 ${W > 180 ? 1 : 0},1 ${R},${c}`;
  };
  return /* @__PURE__ */ e("div", { className: `nice-bargauge ${x || ""}`, style: N, children: /* @__PURE__ */ $("svg", { width: i, height: n, children: [
    w && /* @__PURE__ */ e("text", { x: g, y: 20, textAnchor: "middle", className: "nice-chart__title", children: w }),
    t.map((_, C) => {
      const u = v - C * (b + r), L = Math.max(0, Math.min(1, (_.value - h) / (o - h || 1))), s = p - L * l, R = _.color || me[C % me.length];
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("path", { d: S(u, p, f), fill: "none", stroke: "var(--border-color, #e2e8f0)", strokeWidth: b, strokeLinecap: "round" }),
        L > 0 && /* @__PURE__ */ e("path", { d: S(u, p, s), fill: "none", stroke: R, strokeWidth: b, strokeLinecap: "round" })
      ] }, C);
    }),
    /* @__PURE__ */ e("g", { children: t.map((_, C) => /* @__PURE__ */ $("text", { x: g, y: y - ((t.length - 1) / 2 - C) * 16, textAnchor: "middle", dominantBaseline: "middle", className: "nice-gauge__value", style: { fontSize: 12 }, children: [
      _.label ? `${_.label}: ` : "",
      A ? A(_.value) : _.value
    ] }, C)) })
  ] }) });
}, ct = ({
  data: t,
  width: h = 120,
  height: o = 30,
  type: i = "line",
  color: n = "#3b82f6",
  showMinMax: p,
  showLastPoint: f = !0,
  className: A,
  style: w
}) => {
  if (t.length === 0) return null;
  const x = 2, N = Math.min(...t), g = Math.max(...t), y = g - N || 1, v = h - x * 2, b = o - x * 2, r = (u) => x + u / (t.length - 1 || 1) * v, d = (u) => x + b - (u - N) / y * b;
  if (i === "bar") {
    const u = Math.max(1, v / t.length - 1);
    return /* @__PURE__ */ e("svg", { width: h, height: o, className: `nice-sparkline ${A || ""}`, style: w, children: t.map((L, s) => /* @__PURE__ */ e("rect", { x: x + s / t.length * v, y: d(L), width: u, height: b - (d(L) - x), fill: n, rx: 1 }, s)) });
  }
  const l = t.map((u, L) => `${r(L)},${d(u)}`).join(" "), S = t.indexOf(N), _ = t.indexOf(g), C = t.length - 1;
  return /* @__PURE__ */ $("svg", { width: h, height: o, className: `nice-sparkline ${A || ""}`, style: w, children: [
    i === "area" && /* @__PURE__ */ e("polygon", { points: `${r(0)},${x + b} ${l} ${r(C)},${x + b}`, fill: n, opacity: 0.15 }),
    /* @__PURE__ */ e("polyline", { points: l, fill: "none", stroke: n, strokeWidth: 1.5 }),
    p && /* @__PURE__ */ e("circle", { cx: r(S), cy: d(N), r: 2, fill: "#ef4444" }),
    p && /* @__PURE__ */ e("circle", { cx: r(_), cy: d(g), r: 2, fill: "#22c55e" }),
    f && /* @__PURE__ */ e("circle", { cx: r(C), cy: d(t[C]), r: 2, fill: n })
  ] });
}, st = ({
  value: t,
  target: h,
  min: o = 0,
  max: i = 100,
  width: n = 200,
  height: p = 30,
  color: f = "#3b82f6",
  targetColor: A = "#ef4444",
  className: w,
  style: x
}) => {
  const N = n - 8, g = p - 8, y = Math.max(0, Math.min(1, (t - o) / (i - o || 1))), v = h != null ? Math.max(0, Math.min(1, (h - o) / (i - o || 1))) : null;
  return /* @__PURE__ */ $("svg", { width: n, height: p, className: `nice-bullet ${w || ""}`, style: x, children: [
    /* @__PURE__ */ e("rect", { x: 4, y: 4, width: N, height: g, rx: 3, fill: "var(--border-color, #e2e8f0)" }),
    /* @__PURE__ */ e("rect", { x: 4, y: 4 + g * 0.2, width: N * y, height: g * 0.6, rx: 2, fill: f }),
    v != null && /* @__PURE__ */ e("line", { x1: 4 + N * v, y1: 6, x2: 4 + N * v, y2: 4 + g - 2, stroke: A, strokeWidth: 2 })
  ] });
}, ht = ({
  data: t,
  width: h = 400,
  height: o = 300,
  inverted: i,
  showLabels: n = !0,
  showValues: p = !0,
  title: f,
  className: A,
  style: w
}) => {
  const x = { top: f ? 30 : 10, bottom: 10, x: 40 }, N = h - x.x * 2, g = o - x.top - x.bottom, y = i ? [...t].reverse() : t, v = Math.max(...y.map((r) => r.value), 1), b = g / y.length;
  return /* @__PURE__ */ e("div", { className: `nice-funnel ${A || ""}`, style: w, children: /* @__PURE__ */ $("svg", { width: h, height: o, children: [
    f && /* @__PURE__ */ e("text", { x: h / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: f }),
    y.map((r, d) => {
      const l = r.value / v * N, S = d < y.length - 1 ? y[d + 1].value / v * N : l * 0.3, _ = x.top + d * b, C = _ + b, u = h / 2, L = `${u - l / 2},${_} ${u + l / 2},${_} ${u + S / 2},${C} ${u - S / 2},${C}`, s = r.color || me[d % me.length];
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("polygon", { points: L, fill: s, stroke: "var(--bg-primary, #fff)", strokeWidth: 1, children: /* @__PURE__ */ e("title", { children: `${r.label}: ${r.value}` }) }),
        n && /* @__PURE__ */ e("text", { x: u, y: _ + b / 2 - (p ? 4 : 0), textAnchor: "middle", dominantBaseline: "middle", className: "nice-funnel__label", children: r.label }),
        p && /* @__PURE__ */ e("text", { x: u, y: _ + b / 2 + 10, textAnchor: "middle", dominantBaseline: "middle", className: "nice-funnel__value", children: r.value })
      ] }, d);
    })
  ] }) });
}, Ve = ({
  nodes: t,
  links: h,
  width: o = 600,
  height: i = 400,
  nodeWidth: n = 20,
  nodePadding: p = 10,
  title: f,
  className: A,
  style: w
}) => {
  const x = { top: f ? 40 : 20, bottom: 20, left: 20, right: 20 }, N = o - x.left - x.right, g = i - x.top - x.bottom, y = new Set(h.map((c) => c.source)), v = new Set(h.map((c) => c.target)), b = t.filter((c) => y.has(c.id) && !v.has(c.id)), r = t.filter((c) => v.has(c.id)), d = t.filter((c) => y.has(c.id) && v.has(c.id)), l = [b, ...d.length ? [d] : [], r].filter((c) => c.length > 0), S = l.length, _ = /* @__PURE__ */ new Map();
  t.forEach((c) => {
    const W = h.filter((Y) => Y.source === c.id).reduce((Y, U) => Y + U.value, 0), z = h.filter((Y) => Y.target === c.id).reduce((Y, U) => Y + U.value, 0);
    _.set(c.id, Math.max(W, z));
  });
  const C = l.map((c) => c.reduce((W, z) => W + (_.get(z.id) || 0), 0) + (c.length - 1) * p), u = Math.max(...C, 1), L = /* @__PURE__ */ new Map();
  l.forEach((c, W) => {
    const z = x.left + W / (S - 1 || 1) * (N - n);
    let Y = 0;
    c.forEach((U) => {
      const B = (_.get(U.id) || 0) / u * g;
      L.set(U.id, { x: z, y: x.top + Y, h: B }), Y += B + p;
    });
  });
  const s = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
  return t.forEach((c) => {
    s.set(c.id, 0), R.set(c.id, 0);
  }), /* @__PURE__ */ e("div", { className: `nice-sankey ${A || ""}`, style: w, children: /* @__PURE__ */ $("svg", { width: o, height: i, children: [
    f && /* @__PURE__ */ e("text", { x: o / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: f }),
    h.map((c, W) => {
      var I;
      const z = L.get(c.source), Y = L.get(c.target);
      if (!z || !Y) return null;
      const U = s.get(c.source) || 0, B = R.get(c.target) || 0, Z = c.value / u * g;
      s.set(c.source, U + Z), R.set(c.target, B + Z);
      const V = z.x + n, J = z.y + U, E = Y.x, oe = Y.y + B, K = (V + E) / 2, ae = ((I = t.find((j) => j.id === c.source)) == null ? void 0 : I.color) || me[W % me.length];
      return /* @__PURE__ */ e(
        "path",
        {
          d: `M${V},${J} C${K},${J} ${K},${oe} ${E},${oe} L${E},${oe + Z} C${K},${oe + Z} ${K},${J + Z} ${V},${J + Z} Z`,
          fill: ae,
          fillOpacity: 0.3,
          stroke: ae,
          strokeOpacity: 0.5,
          strokeWidth: 0.5,
          children: /* @__PURE__ */ e("title", { children: `${c.source} → ${c.target}: ${c.value}` })
        },
        W
      );
    }),
    t.map((c, W) => {
      const z = L.get(c.id);
      if (!z) return null;
      const Y = c.color || me[W % me.length];
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("rect", { x: z.x, y: z.y, width: n, height: Math.max(z.h, 2), fill: Y, rx: 2 }),
        /* @__PURE__ */ e(
          "text",
          {
            x: z.x < N / 2 ? z.x + n + 4 : z.x - 4,
            y: z.y + z.h / 2,
            textAnchor: z.x < N / 2 ? "start" : "end",
            dominantBaseline: "middle",
            className: "nice-chart__legend-text",
            children: c.label
          }
        )
      ] }, c.id);
    })
  ] }) });
}, dt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceSankey: Ve
}, Symbol.toStringTag, { value: "Module" })), mt = ({
  data: t,
  min: h,
  max: o,
  start: i,
  end: n,
  onChange: p,
  width: f = 500,
  height: A = 100,
  step: w = 1,
  formatValue: x,
  chartColor: N = "#3b82f6",
  className: g,
  style: y
}) => {
  const v = { top: 10, bottom: 30, left: 10, right: 10 }, b = f - v.left - v.right, r = A - v.top - v.bottom, d = (u) => v.left + (u - h) / (o - h || 1) * b, l = (u) => {
    const L = Math.max(0, Math.min(1, (u - v.left) / b)), s = h + L * (o - h);
    return Math.round(s / w) * w;
  }, S = (u, L) => {
    L.preventDefault();
    const s = L.target.closest("svg");
    if (!s) return;
    const R = (W) => {
      const z = s.getBoundingClientRect(), Y = l(W.clientX - z.left);
      u === "start" ? p(Math.min(Y, n), n) : p(i, Math.max(Y, i));
    }, c = () => {
      document.removeEventListener("pointermove", R), document.removeEventListener("pointerup", c);
    };
    document.addEventListener("pointermove", R), document.addEventListener("pointerup", c);
  }, _ = t ? Math.min(...t) : 0, C = (t ? Math.max(...t) : 1) - _ || 1;
  return /* @__PURE__ */ e("div", { className: `nice-rangeselector ${g || ""}`, style: y, children: /* @__PURE__ */ $("svg", { width: f, height: A, children: [
    t && t.length > 1 && /* @__PURE__ */ e(
      "polygon",
      {
        points: `${v.left},${v.top + r} ${t.map((u, L) => `${v.left + L / (t.length - 1) * b},${v.top + r - (u - _) / C * r}`).join(" ")} ${v.left + b},${v.top + r}`,
        fill: N,
        opacity: 0.15
      }
    ),
    /* @__PURE__ */ e("rect", { x: d(i), y: v.top, width: d(n) - d(i), height: r, fill: N, opacity: 0.1 }),
    /* @__PURE__ */ e("rect", { x: v.left, y: v.top, width: d(i) - v.left, height: r, fill: "var(--bg-secondary, #f5f5f5)", opacity: 0.6 }),
    /* @__PURE__ */ e("rect", { x: d(n), y: v.top, width: v.left + b - d(n), height: r, fill: "var(--bg-secondary, #f5f5f5)", opacity: 0.6 }),
    /* @__PURE__ */ e(
      "rect",
      {
        x: d(i) - 4,
        y: v.top,
        width: 8,
        height: r,
        fill: N,
        rx: 2,
        cursor: "ew-resize",
        onPointerDown: (u) => S("start", u)
      }
    ),
    /* @__PURE__ */ e(
      "rect",
      {
        x: d(n) - 4,
        y: v.top,
        width: 8,
        height: r,
        fill: N,
        rx: 2,
        cursor: "ew-resize",
        onPointerDown: (u) => S("end", u)
      }
    ),
    /* @__PURE__ */ e("text", { x: d(i), y: v.top + r + 18, textAnchor: "middle", className: "nice-chart__axis-label", children: x ? x(i) : i }),
    /* @__PURE__ */ e("text", { x: d(n), y: v.top + r + 18, textAnchor: "middle", className: "nice-chart__axis-label", children: x ? x(n) : n })
  ] }) });
}, Ee = ({
  regions: t,
  width: h = 600,
  height: o = 400,
  viewBox: i = "0 0 1000 600",
  colorRange: n = ["#dbeafe", "#1d4ed8"],
  maxValue: p,
  onRegionClick: f,
  selectedRegionId: A,
  title: w,
  showTooltip: x = !0,
  className: N,
  style: g
}) => {
  const y = p ?? Math.max(...t.map((b) => b.value ?? 0), 1), v = (b) => {
    const r = (c) => [parseInt(c.slice(1, 3), 16), parseInt(c.slice(3, 5), 16), parseInt(c.slice(5, 7), 16)], [d, l, S] = r(n[0]), [_, C, u] = r(n[1]), L = Math.round(d + (_ - d) * b), s = Math.round(l + (C - l) * b), R = Math.round(S + (u - S) * b);
    return `rgb(${L},${s},${R})`;
  };
  return /* @__PURE__ */ $("div", { className: `nice-vectormap ${N || ""}`, style: g, children: [
    w && /* @__PURE__ */ e("div", { className: "nice-vectormap__title", children: w }),
    /* @__PURE__ */ e("svg", { width: h, height: o, viewBox: i, children: t.map((b) => {
      const r = b.value != null ? Math.max(0, Math.min(1, b.value / y)) : 0, d = b.value != null ? v(r) : "var(--bg-tertiary, #e5e7eb)", l = b.id === A;
      return /* @__PURE__ */ e(
        "path",
        {
          d: b.path,
          fill: d,
          stroke: l ? "var(--color-primary, #3b82f6)" : "var(--border-color, #d1d5db)",
          strokeWidth: l ? 2 : 0.5,
          cursor: f ? "pointer" : void 0,
          onClick: () => f == null ? void 0 : f(b),
          children: x && /* @__PURE__ */ e("title", { children: `${b.name}${b.value != null ? `: ${b.value}` : ""}` })
        },
        b.id
      );
    }) })
  ] });
}, ft = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  NiceVectorMap: Ee
}, Symbol.toStringTag, { value: "Module" })), Xe = `
.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);
}
`, Be = [
  "#3b82f6",
  // blue
  "#10b981",
  // green
  "#f59e0b",
  // amber
  "#ef4444",
  // red
  "#8b5cf6",
  // purple
  "#ec4899",
  // pink
  "#06b6d4",
  // cyan
  "#f97316"
  // orange
];
function he(t) {
  return t instanceof Date ? t : new Date(t);
}
function Ie(t, h = "pl-PL") {
  return t.toLocaleDateString(h, {
    year: "numeric",
    month: "short",
    day: "numeric"
  });
}
function Me(t, h = "pl-PL") {
  return new Intl.NumberFormat(h, {
    minimumFractionDigits: 0,
    maximumFractionDigits: 2
  }).format(t);
}
_e(
  function(t, h) {
    var F, ne;
    const {
      scenarios: o,
      annotations: i = [],
      referenceLines: n = [],
      forecastStartDate: p,
      cashRunway: f,
      xAxis: A,
      yAxis: w,
      confidenceBands: x = [{ level: 95, color: "#3b82f6", opacity: 0.15 }],
      tooltip: N,
      legend: g = { enabled: !0, position: "bottom", interactive: !0 },
      height: y = 350,
      showForecastRegion: v = !0,
      lineWidth: b = 2,
      showPoints: r = !1,
      pointRadius: d = 4,
      enableZoom: l = !1,
      animationDuration: S = 300,
      responsive: _ = !0,
      onPointClick: C,
      onAnnotationClick: u,
      onScenarioToggle: L,
      onViewportChange: s,
      size: R = "medium",
      disabled: c = !1,
      labels: W = {},
      locale: z = "pl-PL",
      className: Y,
      style: U
    } = t, [B, Z] = ce(
      () => o.map((a, M) => ({
        ...a,
        color: a.color ?? Be[M % Be.length],
        visible: a.visible !== !1
      }))
    ), [V, J] = ce(null), [E, oe] = ce({ x: 0, y: 0 }), K = be(null), ae = be(null), I = { top: 20, right: 30, bottom: 40, left: 60 }, [j, re] = ce({
      width: 600,
      height: typeof y == "number" ? y : 350
    });
    Ne(() => {
      if (!_ || !K.current) return;
      const a = new ResizeObserver((M) => {
        for (const D of M)
          re((m) => ({
            width: D.contentRect.width,
            height: m.height
          }));
      });
      return a.observe(K.current), () => a.disconnect();
    }, [_]), Ne(() => {
      const a = "nice-forecast-chart-styles";
      if (!document.getElementById(a)) {
        const M = document.createElement("style");
        M.id = a, M.textContent = Xe, document.head.appendChild(M);
      }
    }, []);
    const { xScale: G, yScale: X, allDates: Q, minY: pe, maxY: ve } = fe(() => {
      const a = B.filter((ee) => ee.visible !== !1).flatMap((ee) => ee.data);
      if (a.length === 0)
        return { xScale: () => 0, yScale: () => 0, allDates: [], minY: 0, maxY: 100 };
      const M = a.map((ee) => he(ee.date).getTime()), D = Math.min(...M), m = Math.max(...M), P = a.flatMap((ee) => [ee.value, ee.forecast, ee.lowerBound, ee.upperBound]).filter((ee) => ee != null), ie = (w == null ? void 0 : w.min) ?? Math.min(...P) * 0.95, de = (w == null ? void 0 : w.max) ?? Math.max(...P) * 1.05, se = j.width - I.left - I.right, le = j.height - I.top - I.bottom, we = (ee) => {
        const Ce = typeof ee == "number" ? ee : ee.getTime();
        return I.left + (Ce - D) / (m - D) * se;
      }, Ae = (ee) => I.top + le - (ee - ie) / (de - ie) * le, Se = [...new Set(M)].sort((ee, Ce) => ee - Ce).map((ee) => new Date(ee));
      return {
        xScale: we,
        yScale: Ae,
        allDates: Se,
        minY: ie,
        maxY: de
      };
    }, [B, j, I, w]), ue = p ? he(p) : null, T = fe(() => {
      if (!(f != null && f.enabled)) return null;
      const a = f.threshold ?? 0, M = f.scenarioId ? B.find((m) => m.id === f.scenarioId && m.visible !== !1) : B.find((m) => m.visible !== !1);
      if (!M) return null;
      const D = M.data.sort(
        (m, P) => he(m.date).getTime() - he(P.date).getTime()
      );
      for (let m = 1; m < D.length; m++) {
        const P = D[m - 1], ie = D[m], de = P.forecast ?? P.value, se = ie.forecast ?? ie.value;
        if (de != null && se != null && de > a && se <= a) {
          const le = (de - a) / (de - se), we = he(P.date).getTime(), Ae = he(ie.date).getTime(), Se = we + le * (Ae - we);
          return new Date(Se);
        }
      }
      return null;
    }, [f, B]), O = te(
      (a, M) => {
        const D = a.filter((m) => m[M] != null).map((m) => ({ x: G(he(m.date)), y: X(m[M]) }));
        return D.length === 0 ? "" : `M ${D.map((m) => `${m.x},${m.y}`).join(" L ")}`;
      },
      [G, X]
    ), q = te(
      (a) => {
        const M = a.filter((P) => P.lowerBound != null && P.upperBound != null);
        if (M.length === 0) return "";
        const D = M.map((P) => ({
          x: G(he(P.date)),
          y: X(P.upperBound)
        })), m = M.map((P) => ({ x: G(he(P.date)), y: X(P.lowerBound) })).reverse();
        return `M ${D.map((P) => `${P.x},${P.y}`).join(" L ")} L ${m.map((P) => `${P.x},${P.y}`).join(" L ")} Z`;
      },
      [G, X]
    ), ge = te(
      (a) => {
        if (!ae.current || (N == null ? void 0 : N.enabled) === !1) return;
        const M = ae.current.getBoundingClientRect(), D = a.clientX - M.left;
        a.clientY - M.top;
        let m = null, P = 1 / 0;
        for (const ie of Q) {
          const de = G(ie), se = Math.abs(de - D);
          se < P && (P = se, m = ie);
        }
        if (m && P < 50) {
          const ie = B.filter((se) => se.visible !== !1).map((se) => {
            const le = se.data.find((we) => he(we.date).getTime() === m.getTime());
            return {
              scenario: se,
              value: le == null ? void 0 : le.value,
              forecast: le == null ? void 0 : le.forecast,
              lowerBound: le == null ? void 0 : le.lowerBound,
              upperBound: le == null ? void 0 : le.upperBound
            };
          }), de = i.filter(
            (se) => Math.abs(he(se.date).getTime() - m.getTime()) < 864e5
          );
          J({ date: m, values: ie, annotations: de }), oe({ x: a.clientX - M.left + 10, y: a.clientY - M.top - 10 });
        } else
          J(null);
      },
      [G, Q, B, i, N]
    ), xe = te(
      (a) => {
        if (!g.interactive) return;
        Z((D) => D.map((m) => m.id === a ? { ...m, visible: !m.visible } : m));
        const M = B.find((D) => D.id === a);
        M && (L == null || L(a, !M.visible));
      },
      [g.interactive, B, L]
    );
    ze(
      h,
      () => ({
        getScenarios: () => B,
        updateScenario: (a, M) => {
          Z((D) => D.map((m) => m.id === a ? { ...m, data: M } : m));
        },
        toggleScenario: xe,
        setZoomRange: () => {
        },
        // Would need pan/zoom implementation
        resetZoom: () => {
        },
        exportImage: (a) => {
          if (!ae.current) return null;
          const M = ae.current, D = new XMLSerializer().serializeToString(M);
          return `data:image/svg+xml;base64,${btoa(D)}`;
        },
        getDataAtDate: (a) => {
          const M = B.filter((D) => D.visible !== !1).map((D) => {
            const m = D.data.find((P) => he(P.date).getTime() === a.getTime());
            return {
              scenario: D,
              value: m == null ? void 0 : m.value,
              forecast: m == null ? void 0 : m.forecast,
              lowerBound: m == null ? void 0 : m.lowerBound,
              upperBound: m == null ? void 0 : m.upperBound
            };
          });
          return {
            date: a,
            values: M,
            annotations: i.filter((D) => he(D.date).getTime() === a.getTime())
          };
        }
      }),
      [B, i, xe]
    ), j.width - I.left - I.right;
    const ye = j.height - I.top - I.bottom, k = fe(() => {
      const a = (w == null ? void 0 : w.tickCount) ?? 5, M = [], D = (ve - pe) / (a - 1);
      for (let m = 0; m < a; m++)
        M.push(pe + D * m);
      return M;
    }, [pe, ve, w == null ? void 0 : w.tickCount]), H = fe(() => {
      const a = (A == null ? void 0 : A.tickCount) ?? 6;
      if (Q.length === 0) return [];
      const M = Math.max(1, Math.floor(Q.length / (a - 1)));
      return Q.filter((D, m) => m % M === 0 || m === Q.length - 1);
    }, [Q, A == null ? void 0 : A.tickCount]);
    return B.length === 0 || B.every((a) => a.data.length === 0) ? /* @__PURE__ */ e("div", { className: `nice-forecast-chart ${Y ?? ""}`, style: U, children: /* @__PURE__ */ e("div", { className: "nice-forecast-chart__empty", children: W.noData ?? "No data available" }) }) : /* @__PURE__ */ $("div", { className: `nice-forecast-chart ${Y ?? ""}`, style: { ...U, height: y }, children: [
      /* @__PURE__ */ $("div", { ref: K, className: "nice-forecast-chart__container", children: [
        /* @__PURE__ */ $(
          "svg",
          {
            ref: ae,
            className: "nice-forecast-chart__svg",
            width: j.width,
            height: j.height,
            onMouseMove: ge,
            onMouseLeave: () => J(null),
            children: [
              (w == null ? void 0 : w.showGrid) !== !1 && k.map((a) => /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__grid-line",
                  x1: I.left,
                  x2: j.width - I.right,
                  y1: X(a),
                  y2: X(a)
                },
                a
              )),
              v && ue && /* @__PURE__ */ e(
                "rect",
                {
                  className: "nice-forecast-chart__forecast-region",
                  x: G(ue),
                  y: I.top,
                  width: j.width - I.right - G(ue),
                  height: ye
                }
              ),
              n.map((a) => /* @__PURE__ */ $("g", { children: [
                /* @__PURE__ */ e(
                  "line",
                  {
                    className: "nice-forecast-chart__reference-line",
                    x1: I.left,
                    x2: j.width - I.right,
                    y1: X(a.value),
                    y2: X(a.value),
                    stroke: a.color ?? "#9ca3af",
                    strokeDasharray: a.dashArray ?? "4,2"
                  }
                ),
                a.label && /* @__PURE__ */ e(
                  "text",
                  {
                    className: "nice-forecast-chart__reference-label",
                    x: j.width - I.right - 4,
                    y: X(a.value) - 4,
                    textAnchor: "end",
                    children: a.label
                  }
                )
              ] }, a.id)),
              T && (f == null ? void 0 : f.enabled) && /* @__PURE__ */ $("g", { className: "nice-forecast-chart__cash-runway", children: [
                /* @__PURE__ */ e(
                  "line",
                  {
                    className: "nice-forecast-chart__cash-runway-line",
                    x1: G(T),
                    x2: G(T),
                    y1: I.top,
                    y2: j.height - I.bottom,
                    stroke: f.color ?? "#ef4444"
                  }
                ),
                f.showLabel !== !1 && /* @__PURE__ */ $(Te, { children: [
                  /* @__PURE__ */ e(
                    "rect",
                    {
                      className: "nice-forecast-chart__cash-runway-label-bg",
                      x: G(T) - 60,
                      y: I.top - 2,
                      width: 120,
                      height: f.showDate !== !1 ? 32 : 20,
                      fill: f.color ?? "#ef4444",
                      rx: 4
                    }
                  ),
                  /* @__PURE__ */ e(
                    "text",
                    {
                      className: "nice-forecast-chart__cash-runway-label",
                      x: G(T),
                      y: I.top + 12,
                      textAnchor: "middle",
                      fill: "#ffffff",
                      children: f.label ?? W.cashRunsOut ?? "💰 Cash runs out"
                    }
                  ),
                  f.showDate !== !1 && /* @__PURE__ */ e(
                    "text",
                    {
                      className: "nice-forecast-chart__cash-runway-label",
                      x: G(T),
                      y: I.top + 26,
                      textAnchor: "middle",
                      fill: "#ffffff",
                      style: { fontSize: "0.625rem", opacity: 0.9 },
                      children: Ie(T, z)
                    }
                  )
                ] })
              ] }),
              B.filter((a) => a.visible !== !1 && a.showConfidenceBand).map((a) => /* @__PURE__ */ e(
                "path",
                {
                  className: "nice-forecast-chart__confidence-band",
                  d: q(a.data),
                  fill: a.color
                },
                `band-${a.id}`
              )),
              B.filter((a) => a.visible !== !1).map((a) => {
                const M = ue ? a.data.filter((m) => he(m.date) < ue) : a.data.filter((m) => m.value != null), D = ue ? a.data.filter((m) => he(m.date) >= ue) : a.data.filter((m) => m.forecast != null);
                return /* @__PURE__ */ $("g", { children: [
                  /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__historical-line",
                      d: O(M, "value"),
                      stroke: a.color,
                      strokeWidth: b
                    }
                  ),
                  /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__forecast-line",
                      d: O(D, ue ? "value" : "forecast"),
                      stroke: a.color,
                      strokeWidth: b
                    }
                  ),
                  D.length > 0 && a.data.some((m) => m.forecast != null) && /* @__PURE__ */ e(
                    "path",
                    {
                      className: "nice-forecast-chart__forecast-line",
                      d: O(a.data, "forecast"),
                      stroke: a.color,
                      strokeWidth: b
                    }
                  ),
                  r && a.data.map((m, P) => {
                    const ie = m.value ?? m.forecast;
                    return ie == null ? null : /* @__PURE__ */ e(
                      "circle",
                      {
                        className: "nice-forecast-chart__point",
                        cx: G(he(m.date)),
                        cy: X(ie),
                        r: d,
                        fill: a.color,
                        onClick: () => C == null ? void 0 : C(m, a)
                      },
                      P
                    );
                  })
                ] }, a.id);
              }),
              i.map((a) => {
                const M = G(he(a.date));
                return /* @__PURE__ */ $(
                  "g",
                  {
                    className: "nice-forecast-chart__annotation-marker",
                    onClick: () => u == null ? void 0 : u(a),
                    children: [
                      a.showLine !== !1 && /* @__PURE__ */ e(
                        "line",
                        {
                          className: "nice-forecast-chart__annotation-line",
                          x1: M,
                          x2: M,
                          y1: I.top,
                          y2: j.height - I.bottom,
                          stroke: a.color ?? "#9ca3af"
                        }
                      ),
                      /* @__PURE__ */ e("circle", { cx: M, cy: I.top + 10, r: 8, fill: a.color ?? "#9ca3af" }),
                      /* @__PURE__ */ e("text", { x: M, y: I.top + 14, textAnchor: "middle", fill: "white", fontSize: "10", children: a.icon ?? "!" })
                    ]
                  },
                  a.id
                );
              }),
              /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__axis-line",
                  x1: I.left,
                  x2: I.left,
                  y1: I.top,
                  y2: j.height - I.bottom
                }
              ),
              /* @__PURE__ */ e(
                "line",
                {
                  className: "nice-forecast-chart__axis-line",
                  x1: I.left,
                  x2: j.width - I.right,
                  y1: j.height - I.bottom,
                  y2: j.height - I.bottom
                }
              ),
              k.map((a) => /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-label",
                  x: I.left - 8,
                  y: X(a) + 4,
                  textAnchor: "end",
                  children: w != null && w.format ? w.format(a) : Me(a, z)
                },
                a
              )),
              H.map((a) => /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-label",
                  x: G(a),
                  y: j.height - I.bottom + 16,
                  textAnchor: "middle",
                  children: A != null && A.format ? A.format(a) : Ie(a, z)
                },
                a.getTime()
              )),
              (w == null ? void 0 : w.title) && /* @__PURE__ */ e(
                "text",
                {
                  className: "nice-forecast-chart__axis-title",
                  x: 15,
                  y: j.height / 2,
                  textAnchor: "middle",
                  transform: `rotate(-90, 15, ${j.height / 2})`,
                  children: w.title
                }
              )
            ]
          }
        ),
        V && /* @__PURE__ */ $(
          "div",
          {
            className: "nice-forecast-chart__tooltip",
            style: { left: E.x, top: E.y },
            children: [
              /* @__PURE__ */ e("div", { className: "nice-forecast-chart__tooltip-date", children: Ie(V.date, z) }),
              V.values.map((a) => {
                const M = a.value ?? a.forecast;
                return M == null ? null : /* @__PURE__ */ $("div", { className: "nice-forecast-chart__tooltip-item", children: [
                  /* @__PURE__ */ e(
                    "span",
                    {
                      className: "nice-forecast-chart__tooltip-color",
                      style: { background: a.scenario.color }
                    }
                  ),
                  /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-label", children: a.scenario.name }),
                  /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-value", children: Me(M, z) })
                ] }, a.scenario.id);
              }),
              V.values.some((a) => a.lowerBound != null) && /* @__PURE__ */ $("div", { className: "nice-forecast-chart__tooltip-confidence", children: [
                W.confidence ?? "CI",
                ":",
                " ",
                Me(((F = V.values[0]) == null ? void 0 : F.lowerBound) ?? 0, z),
                " –",
                " ",
                Me(((ne = V.values[0]) == null ? void 0 : ne.upperBound) ?? 0, z)
              ] })
            ]
          }
        )
      ] }),
      g.enabled && /* @__PURE__ */ e("div", { className: "nice-forecast-chart__legend", children: B.map((a) => /* @__PURE__ */ $(
        "div",
        {
          className: `nice-forecast-chart__legend-item ${a.visible === !1 ? "nice-forecast-chart__legend-item--hidden" : ""}`,
          onClick: () => xe(a.id),
          children: [
            /* @__PURE__ */ e(
              "span",
              {
                className: `nice-forecast-chart__legend-color ${a.isBase ? "" : "nice-forecast-chart__legend-color--dashed"}`,
                style: { background: a.color }
              }
            ),
            a.name
          ]
        },
        a.id
      )) })
    ] });
  }
);
const He = _e(({
  data: t,
  renderNode: h,
  selectable: o,
  selectedKey: i,
  onSelect: n,
  direction: p = "top-down",
  collapsible: f = !0,
  className: A,
  style: w,
  id: x
}, N) => {
  const g = $e(x), [y, v] = ce(/* @__PURE__ */ new Set()), b = te((l) => {
    v((S) => {
      const _ = new Set(S);
      return _.has(l) ? _.delete(l) : _.add(l), _;
    });
  }, []), r = te((l) => {
    o && (n == null || n(l));
  }, [o, n]), d = te((l) => {
    const S = y.has(l.key), _ = l.children && l.children.length > 0;
    return /* @__PURE__ */ $("li", { className: "nice-org-chart__item", children: [
      /* @__PURE__ */ $(
        "div",
        {
          className: `nice-org-chart__node${i === l.key ? " nice-org-chart__node--selected" : ""}`,
          onClick: () => r(l.key),
          role: o ? "button" : void 0,
          children: [
            h ? h(l) : /* @__PURE__ */ e("span", { children: l.label }),
            f && _ && /* @__PURE__ */ e(
              "button",
              {
                type: "button",
                className: "nice-org-chart__toggle",
                onClick: (C) => {
                  C.stopPropagation(), b(l.key);
                },
                "aria-label": S ? "Expand" : "Collapse",
                children: S ? "+" : "−"
              }
            )
          ]
        }
      ),
      _ && !S && /* @__PURE__ */ e("ul", { className: "nice-org-chart__children", children: l.children.map((C) => d(C)) })
    ] }, l.key);
  }, [y, i, h, o, f, r, b]);
  return /* @__PURE__ */ e(
    "div",
    {
      ref: N,
      id: g,
      className: `nice-org-chart nice-org-chart--${p} ${A || ""}`,
      style: w,
      children: /* @__PURE__ */ e("ul", { className: "nice-org-chart__root", children: d(t) })
    }
  );
});
He.displayName = "NiceOrganizationChart";
function Ze(t, h, o) {
  const i = (v) => {
    const b = v.replace("#", "");
    return [parseInt(b.slice(0, 2), 16), parseInt(b.slice(2, 4), 16), parseInt(b.slice(4, 6), 16)];
  }, [n, p, f] = i(t), [A, w, x] = i(h), N = Math.round(n + (A - n) * o), g = Math.round(p + (w - p) * o), y = Math.round(f + (x - f) * o);
  return `rgb(${N},${g},${y})`;
}
const Ge = _e(({
  data: t,
  xLabels: h,
  yLabels: o,
  colors: i = ["#e0f2fe", "#1d4ed8"],
  onCellClick: n,
  cellSize: p = 40,
  showValues: f = !0,
  className: A,
  style: w,
  id: x
}, N) => {
  const g = $e(x), { minVal: y, maxVal: v } = fe(() => {
    let r = 1 / 0, d = -1 / 0;
    for (const l of t) for (const S of l)
      S < r && (r = S), S > d && (d = S);
    return { minVal: r, maxVal: d };
  }, [t]), b = te((r) => v === y ? 0.5 : (r - y) / (v - y), [y, v]);
  return /* @__PURE__ */ e("div", { ref: N, id: g, className: `nice-heatmap ${A || ""}`, style: w, children: /* @__PURE__ */ $("table", { className: "nice-heatmap__table", children: [
    h && /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ $("tr", { children: [
      o && /* @__PURE__ */ e("th", {}),
      h.map((r, d) => /* @__PURE__ */ e("th", { className: "nice-heatmap__header", children: r }, d))
    ] }) }),
    /* @__PURE__ */ e("tbody", { children: t.map((r, d) => /* @__PURE__ */ $("tr", { children: [
      o && /* @__PURE__ */ e("th", { className: "nice-heatmap__row-label", children: o[d] }),
      r.map((l, S) => /* @__PURE__ */ e(
        "td",
        {
          className: "nice-heatmap__cell",
          style: {
            background: Ze(i[0], i[1], b(l)),
            width: p,
            height: p,
            textAlign: "center",
            color: b(l) > 0.6 ? "#fff" : "#333",
            cursor: n ? "pointer" : void 0
          },
          onClick: () => n == null ? void 0 : n(d, S, l),
          title: String(l),
          children: f ? l : ""
        },
        S
      ))
    ] }, d)) })
  ] }) });
});
Ge.displayName = "NiceHeatMap";
function Ue(t, h) {
  const o = t.reduce((x, N) => x + N.value, 0);
  if (o === 0 || t.length === 0) return [];
  const i = [];
  let { x: n, y: p, w: f, h: A } = h;
  const w = [...t].sort((x, N) => N.value - x.value);
  for (const x of w) {
    const N = x.value / o;
    if (f >= A) {
      const g = f * N;
      i.push({ x: n, y: p, w: g, h: A, node: x }), n += g, f -= g;
    } else {
      const g = A * N;
      i.push({ x: n, y: p, w: f, h: g, node: x }), p += g, A -= g;
    }
  }
  return i;
}
const Je = ["#3b82f6", "#10b981", "#f59e0b", "#ef4444", "#8b5cf6", "#06b6d4", "#ec4899", "#84cc16"], qe = _e(({
  data: t,
  width: h = 600,
  height: o = 400,
  onNodeClick: i,
  colors: n = Je,
  className: p,
  style: f,
  id: A
}, w) => {
  const x = $e(A), N = fe(() => {
    const g = t.children ?? [t];
    return Ue(g, { x: 0, y: 0, w: h, h: o });
  }, [t, h, o]);
  return /* @__PURE__ */ e("div", { ref: w, id: x, className: `nice-treemap ${p || ""}`, style: f, children: /* @__PURE__ */ e("svg", { width: h, height: o, className: "nice-treemap__svg", children: N.map((g, y) => /* @__PURE__ */ $("g", { onClick: () => i == null ? void 0 : i(g.node), style: { cursor: i ? "pointer" : void 0 }, children: [
    /* @__PURE__ */ e(
      "rect",
      {
        x: g.x,
        y: g.y,
        width: Math.max(g.w - 1, 0),
        height: Math.max(g.h - 1, 0),
        fill: g.node.color ?? n[y % n.length],
        rx: 2
      }
    ),
    g.w > 40 && g.h > 20 && /* @__PURE__ */ e(
      "text",
      {
        x: g.x + g.w / 2,
        y: g.y + g.h / 2,
        textAnchor: "middle",
        dominantBaseline: "central",
        fill: "#fff",
        fontSize: Math.min(12, g.w / 6),
        className: "nice-treemap__label",
        children: g.node.label
      }
    )
  ] }, g.node.key)) }) });
});
qe.displayName = "NiceTreeMap";
const Ke = _e(({
  data: t,
  type: h = "candlestick",
  showVolume: o = !0,
  width: i = 800,
  height: n = 400,
  bullColor: p = "#22c55e",
  bearColor: f = "#ef4444",
  className: A,
  style: w,
  id: x
}, N) => {
  const g = $e(x), y = { top: 20, right: 20, bottom: o ? 80 : 30, left: 60 }, v = i - y.left - y.right, b = o ? 50 : 0, r = n - y.top - y.bottom - b, { minP: d, maxP: l, maxVol: S } = fe(() => {
    let s = 1 / 0, R = -1 / 0, c = 0;
    for (const W of t)
      W.low < s && (s = W.low), W.high > R && (R = W.high), W.volume && W.volume > c && (c = W.volume);
    return { minP: s, maxP: R, maxVol: c };
  }, [t]), _ = Math.max(1, v / t.length * 0.7), C = (s) => y.left + (s + 0.5) * (v / t.length), u = (s) => y.top + r - (s - d) / (l - d || 1) * r, L = (s) => n - y.bottom - b + b * (1 - s / (S || 1));
  return /* @__PURE__ */ e("div", { ref: N, id: g, className: `nice-stock-chart ${A || ""}`, style: w, children: /* @__PURE__ */ $("svg", { width: i, height: n, className: "nice-stock-chart__svg", children: [
    [0, 0.25, 0.5, 0.75, 1].map((s) => {
      const R = d + s * (l - d);
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e(
          "line",
          {
            x1: y.left,
            x2: i - y.right,
            y1: u(R),
            y2: u(R),
            stroke: "#e5e7eb",
            strokeDasharray: "2,2"
          }
        ),
        /* @__PURE__ */ e("text", { x: y.left - 4, y: u(R) + 4, textAnchor: "end", fontSize: 10, fill: "#888", children: R.toFixed(2) })
      ] }, s);
    }),
    h === "line" ? /* @__PURE__ */ e(
      "polyline",
      {
        points: t.map((s, R) => `${C(R)},${u(s.close)}`).join(" "),
        fill: "none",
        stroke: p,
        strokeWidth: 1.5
      }
    ) : t.map((s, R) => {
      const c = s.close >= s.open, W = c ? p : f, z = C(R);
      if (h === "ohlc")
        return /* @__PURE__ */ $("g", { children: [
          /* @__PURE__ */ e("line", { x1: z, x2: z, y1: u(s.high), y2: u(s.low), stroke: W, strokeWidth: 1 }),
          /* @__PURE__ */ e("line", { x1: z - _ / 2, x2: z, y1: u(s.open), y2: u(s.open), stroke: W, strokeWidth: 1.5 }),
          /* @__PURE__ */ e("line", { x1: z, x2: z + _ / 2, y1: u(s.close), y2: u(s.close), stroke: W, strokeWidth: 1.5 })
        ] }, R);
      const Y = u(Math.max(s.open, s.close)), U = u(Math.min(s.open, s.close));
      return /* @__PURE__ */ $("g", { children: [
        /* @__PURE__ */ e("line", { x1: z, x2: z, y1: u(s.high), y2: u(s.low), stroke: W, strokeWidth: 1 }),
        /* @__PURE__ */ e(
          "rect",
          {
            x: z - _ / 2,
            y: Y,
            width: _,
            height: Math.max(U - Y, 1),
            fill: c ? "transparent" : W,
            stroke: W,
            strokeWidth: 1
          }
        )
      ] }, R);
    }),
    o && t.map((s, R) => {
      if (!s.volume) return null;
      const c = s.close >= s.open;
      return /* @__PURE__ */ e(
        "rect",
        {
          x: C(R) - _ / 2,
          y: L(s.volume),
          width: _,
          height: n - y.bottom - L(s.volume),
          fill: c ? p : f,
          opacity: 0.3
        },
        `v${R}`
      );
    }),
    t.map((s, R) => R % Math.max(1, Math.floor(t.length / 8)) !== 0 ? null : /* @__PURE__ */ e(
      "text",
      {
        x: C(R),
        y: n - y.bottom + b + 14,
        textAnchor: "middle",
        fontSize: 9,
        fill: "#888",
        children: s.date
      },
      `l${R}`
    ))
  ] }) });
});
Ke.displayName = "NiceStockChart";
export {
  me as C,
  ot as N,
  st as a,
  De as b,
  it as d,
  ht as f,
  Ge as g,
  lt as h,
  Fe as i,
  He as j,
  rt as k,
  nt as l,
  mt as m,
  Ve as n,
  ct as o,
  Ke as p,
  qe as q,
  Ee as r,
  at as v,
  dt as w,
  ft as x
};
