import { jsx as d, jsxs as I, Fragment as P } from "react/jsx-runtime";
import { a as p } from "../index-BmAFn37q.mjs";
import { createContext as V, useContext as _, useMemo as h, useId as z } from "react";
const k = V(null), w = () => {
  const e = _(k);
  if (!e)
    throw new Error("useSegmentedGaugeContext must be used within a SegmentedGauge provider");
  return e;
}, G = ({
  className: e,
  children: a,
  ref: t,
  id: r,
  ...o
}) => {
  const { labelId: n } = w();
  return /* @__PURE__ */ d(
    "span",
    {
      "data-spark-component": "segmented-gauge-label",
      "data-testid": "segmented-gauge-label",
      ref: t,
      id: r || n,
      className: p("default:text-on-surface default:text-body-2", e),
      ...o,
      children: a
    }
  );
};
G.displayName = "SegmentedGauge.Label";
const x = ({
  index: e = 0,
  className: a,
  children: t,
  ref: r,
  ...o
}) => {
  const { size: n, intent: u, customColor: s, currentIndex: g } = w(), m = g !== -1 && e <= g, b = g !== -1 && e === g, f = h(() => {
    if (s)
      return s;
    switch (u) {
      case "main":
        return "var(--color-main)";
      case "support":
        return "var(--color-support)";
      case "basic":
        return "var(--color-basic)";
      case "accent":
        return "var(--color-accent)";
      case "success":
        return "var(--color-success)";
      case "alert":
        return "var(--color-alert)";
      case "danger":
        return "var(--color-error)";
      case "info":
        return "var(--color-info)";
      case "neutral":
        return "var(--color-neutral)";
      default:
        return "var(--color-neutral)";
    }
  }, [u, s]), N = p(
    "border-outline relative rounded-full",
    {
      "h-sz-8 w-sz-24": n === "sm",
      "h-sz-12 w-sz-36": n === "md",
      "default:bg-[var(--gauge-color)]": m,
      "border-sm bg-surface": !m
    },
    a
  ), l = p(
    "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",
    "default:bg-surface default:rounded-full",
    "border-[var(--gauge-color)]",
    {
      "size-sz-12 border-md": n === "sm",
      "size-sz-20 border-lg": n === "md"
    }
  );
  return /* @__PURE__ */ I(
    "div",
    {
      "data-spark-component": "segmented-gauge-segment",
      "data-testid": "segmented-gauge-segment",
      "data-active": m,
      "data-current": b,
      ref: r,
      style: {
        "--gauge-color": f
      },
      className: N,
      ...o,
      children: [
        t,
        b && /* @__PURE__ */ d("div", { className: l, "aria-hidden": "true" })
      ]
    }
  );
};
x.displayName = "SegmentedGauge.Segment";
const y = ({
  className: e,
  children: a,
  ref: t,
  ...r
}) => /* @__PURE__ */ d(
  "div",
  {
    "data-spark-component": "segmented-gauge-track",
    ref: t,
    className: p("gap-sm relative flex rounded-full", e),
    ...r,
    children: a
  }
);
y.displayName = "SegmentedGauge.Track";
const $ = (e, a, t, r) => {
  if (e == null)
    return -1;
  const o = Math.max(a, Math.min(t, e)), u = (t - a) / (r - 1), s = (o - a) / u;
  return Math.max(0, Math.min(r - 1, Math.round(s)));
}, M = ({
  value: e,
  min: a,
  max: t,
  description: r,
  size: o = "md",
  intent: n = "neutral",
  customColor: u,
  id: s,
  "aria-label": g,
  className: m,
  ref: b,
  children: f,
  ...N
}) => {
  const l = t - a + 1, c = h(
    () => $(e, a, t, l),
    [e, a, t, l]
  ), v = z(), L = z(), S = s || L, C = h(() => Array.from({ length: l }, (A, i) => ({
    isActive: c !== -1 && i <= c,
    isCurrent: c !== -1 && i === c
  })), [l, c]), T = h(
    () => ({
      value: e,
      min: a,
      max: t,
      segments: l,
      currentIndex: c,
      size: o,
      intent: n,
      customColor: u,
      labelId: v,
      gaugeId: S
    }),
    [e, a, t, l, c, o, n, u, v, S]
  ), j = e != null ? {
    role: "meter",
    "aria-valuenow": e,
    "aria-valuemin": a,
    "aria-valuemax": t
  } : {
    role: "status"
  };
  return /* @__PURE__ */ d(k.Provider, { value: T, children: /* @__PURE__ */ d(
    "div",
    {
      id: S,
      "data-spark-component": "segmented-gauge",
      ref: b,
      className: p("gap-md flex flex-wrap items-center", m),
      ...j,
      "aria-labelledby": s ? `${S}-label` : void 0,
      "aria-label": s ? void 0 : g,
      "aria-describedby": v,
      ...N,
      children: f ? f({
        segments: C,
        currentIndex: c
      }) : /* @__PURE__ */ I(P, { children: [
        /* @__PURE__ */ d(y, { children: C.map((A, i) => /* @__PURE__ */ d(x, { index: i }, i)) }),
        r && /* @__PURE__ */ d(G, { id: v, children: r })
      ] })
    }
  ) });
};
M.displayName = "SegmentedGauge";
const D = Object.assign(M, {
  Track: y,
  Segment: x,
  Label: G
});
D.displayName = "SegmentedGauge";
y.displayName = "SegmentedGauge.Track";
x.displayName = "SegmentedGauge.Segment";
G.displayName = "SegmentedGauge.Label";
export {
  D as SegmentedGauge
};
//# sourceMappingURL=index.mjs.map
