import { jsx as u } from "react/jsx-runtime";
import { c as y, a as S } from "../index-BmAFn37q.mjs";
import * as $ from "react";
import { createContext as D, useContext as V, useState as A, useMemo as B, useId as T, useCallback as O } from "react";
import { c as q } from "../index-DFZozV_h.mjs";
import { P as L } from "../index-MSR-vgWR.mjs";
import { useMergeRefs as X } from "@spark-ui/hooks/use-merge-refs";
var b = "Progress", P = 100, [j] = q(b), [F, G] = j(b), E = $.forwardRef(
  (e, r) => {
    const {
      __scopeProgress: o,
      value: s = null,
      max: a,
      getValueLabel: i = z,
      ...l
    } = e;
    (a || a === 0) && !I(a) && console.error(U(`${a}`, "Progress"));
    const t = I(a) ? a : P;
    s !== null && !h(s, t) && console.error(H(`${s}`, "Progress"));
    const n = h(s, t) ? s : null, d = m(n) ? i(n, t) : void 0;
    return /* @__PURE__ */ u(F, { scope: o, value: n, max: t, children: /* @__PURE__ */ u(
      L.div,
      {
        "aria-valuemax": t,
        "aria-valuemin": 0,
        "aria-valuenow": m(n) ? n : void 0,
        "aria-valuetext": d,
        role: "progressbar",
        "data-state": C(n, t),
        "data-value": n ?? void 0,
        "data-max": t,
        ...l,
        ref: r
      }
    ) });
  }
);
E.displayName = b;
var w = "ProgressIndicator", R = $.forwardRef(
  (e, r) => {
    const { __scopeProgress: o, ...s } = e, a = G(w, o);
    return /* @__PURE__ */ u(
      L.div,
      {
        "data-state": C(a.value, a.max),
        "data-value": a.value ?? void 0,
        "data-max": a.max,
        ...s,
        ref: r
      }
    );
  }
);
R.displayName = w;
function z(e, r) {
  return `${Math.round(e / r * 100)}%`;
}
function C(e, r) {
  return e == null ? "indeterminate" : e === r ? "complete" : "loading";
}
function m(e) {
  return typeof e == "number";
}
function I(e) {
  return m(e) && !isNaN(e) && e > 0;
}
function h(e, r) {
  return m(e) && !isNaN(e) && e <= r && e >= 0;
}
function U(e, r) {
  return `Invalid prop \`max\` of value \`${e}\` supplied to \`${r}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${P}\`.`;
}
function H(e, r) {
  return `Invalid prop \`value\` of value \`${e}\` supplied to \`${r}\`. The \`value\` prop must be:
  - a positive number
  - less than the value passed to \`max\` (or ${P} if no \`max\` prop is set)
  - \`null\` or \`undefined\` if the progress is indeterminate.

Defaulting to \`null\`.`;
}
const J = y(
  ["relative", "h-sz-4 w-full", "transform-gpu overflow-hidden", "bg-on-background/dim-4"],
  {
    variants: {
      shape: {
        square: [],
        rounded: ["rounded-sm"]
      }
    }
  }
), M = D(null), K = ":progress", x = () => {
  const e = V(M);
  if (!e)
    throw new Error("useProgress must be used within a Progress provider");
  return e;
}, Q = y(["h-full w-full", "transition-transform duration-400"], {
  variants: {
    /**
     * Color scheme of the progress component.
     */
    intent: {
      basic: ["bg-basic"],
      main: ["bg-main"],
      support: ["bg-support"],
      accent: ["bg-accent"],
      success: ["bg-success"],
      alert: ["bg-alert"],
      danger: ["bg-error"],
      info: ["bg-info"],
      neutral: ["bg-neutral"]
    },
    /**
     * Shape of the progress component.
     */
    shape: {
      square: [],
      rounded: ["rounded-sm"]
    },
    /**
     * Sets if the progress value is not determinated.
     */
    isIndeterminate: {
      true: ["absolute", "-translate-x-1/2", "animate-standalone-indeterminate-bar"],
      false: []
    }
  }
}), g = ({
  className: e,
  style: r,
  ref: o,
  onTransitionEnd: s,
  ...a
}) => {
  const { value: i, max: l, intent: t, shape: n, isIndeterminate: d, onComplete: c } = x(), p = (l - i) / l * 100, v = (k) => {
    s?.(k), i >= l && c && !d && c();
  };
  return /* @__PURE__ */ u(
    R,
    {
      "data-spark-component": "progress-indicator",
      className: Q({ className: e, intent: t, shape: n, isIndeterminate: d }),
      style: { ...r, ...!d && { transform: `translateX(-${p}%)` } },
      ref: o,
      onTransitionEnd: v,
      ...a
    }
  );
};
g.displayName = "Progress.Indicator";
const f = ({
  className: e,
  children: r = /* @__PURE__ */ u(g, {}),
  ref: o,
  ...s
}) => {
  const { shape: a } = x();
  return /* @__PURE__ */ u(
    "div",
    {
      "data-spark-component": "progress-bar",
      className: J({ className: e, shape: a }),
      ref: o,
      ...s,
      children: r
    }
  );
};
f.displayName = "Progress.Bar";
const _ = ({
  className: e,
  value: r,
  max: o = 100,
  shape: s = "square",
  intent: a = "basic",
  isIndeterminate: i = !1,
  onComplete: l,
  children: t = /* @__PURE__ */ u(f, {}),
  ref: n,
  ...d
}) => {
  const [c, p] = A(), v = B(() => ({
    value: r ?? 0,
    max: o,
    intent: a,
    shape: s,
    isIndeterminate: i,
    onLabelId: p,
    onComplete: l
  }), [o, r, a, s, i, p, l]);
  return /* @__PURE__ */ u(M.Provider, { "data-spark-component": "progress", value: v, children: /* @__PURE__ */ u(
    E,
    {
      "data-spark-component": "progress",
      ref: n,
      className: S("gap-sm focus-visible:u-outline flex flex-col", e),
      value: r,
      "aria-labelledby": c,
      max: o,
      tabIndex: -1,
      ...d,
      children: t
    }
  ) });
};
_.displayName = "Progress";
const N = ({
  id: e,
  children: r,
  ref: o,
  ...s
}) => {
  const a = `${K}-label-${T()}`, i = e || a, { onLabelId: l } = x(), t = O(
    (d) => {
      l(d ? i : void 0);
    },
    [i, l]
  ), n = X(o, t);
  return /* @__PURE__ */ u(
    "span",
    {
      "data-spark-component": "progress-label",
      id: i,
      className: "text-body-2 text-on-surface",
      ref: n,
      ...s,
      children: r
    }
  );
};
N.displayName = "Progress.Label";
const W = Object.assign(_, {
  Label: N,
  Bar: f,
  Indicator: g
});
W.displayName = "Progress";
f.displayName = "Progress.Bar";
g.displayName = "Progress.Indicator";
N.displayName = "Progress.Label";
export {
  W as Progress
};
//# sourceMappingURL=index.mjs.map
