"use client";
import { jsx as l, jsxs as y } from "react/jsx-runtime";
import { cn as g } from "../../../lib/utils.js";
import * as a from "react";
import { u as L } from "../../../useValueAsRef-LhoZc6As.js";
import { a as $ } from "../../../visuallyHidden-PuyyGHVF.js";
import { f as S, v as F } from "../../../valueToPercent-BBgE4D3L.js";
import { f as j, u as N } from "../../../useRenderElement-DNB2vtF1.js";
import { u as B } from "../../../useIsoLayoutEffect-DpJo20by.js";
import { u as U } from "../../../useBaseUiId-C8Dq0BQq.js";
function H(r, e) {
  const s = U(r);
  return B(() => (e(s), () => {
    e(void 0);
  }), [s, e]), s;
}
const E = /* @__PURE__ */ a.createContext(void 0);
process.env.NODE_ENV !== "production" && (E.displayName = "ProgressRootContext");
function x() {
  const r = a.useContext(E);
  if (r === void 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ProgressRootContext is missing. Progress parts must be placed within <Progress.Root>." : j(51));
  return r;
}
let h = /* @__PURE__ */ (function(r) {
  return r.complete = "data-complete", r.indeterminate = "data-indeterminate", r.progressing = "data-progressing", r;
})({});
const P = {
  status(r) {
    return r === "progressing" ? {
      [h.progressing]: ""
    } : r === "complete" ? {
      [h.complete]: ""
    } : r === "indeterminate" ? {
      [h.indeterminate]: ""
    } : null;
  }
};
function q(r, e) {
  return e == null ? "indeterminate progress" : r || `${e}%`;
}
const w = /* @__PURE__ */ a.forwardRef(function(e, s) {
  const {
    format: u,
    getAriaValueText: m = q,
    locale: i,
    max: n = 100,
    min: o = 0,
    value: t,
    render: d,
    className: c,
    children: f,
    ...b
  } = e, [C, R] = a.useState(), D = L(u);
  let p = "indeterminate";
  Number.isFinite(t) && (p = t === n ? "complete" : "progressing");
  const v = S(t, i, D.current), V = a.useMemo(() => ({
    status: p
  }), [p]), T = {
    "aria-labelledby": C,
    "aria-valuemax": n,
    "aria-valuemin": o,
    "aria-valuenow": t ?? void 0,
    "aria-valuetext": m(v, t),
    role: "progressbar",
    children: /* @__PURE__ */ y(a.Fragment, {
      children: [f, /* @__PURE__ */ l("span", {
        role: "presentation",
        style: $,
        children: "x"
      })]
    })
  }, _ = a.useMemo(() => ({
    formattedValue: v,
    max: n,
    min: o,
    setLabelId: R,
    state: V,
    status: p,
    value: t
  }), [v, n, o, R, V, p, t]), k = N("div", e, {
    state: V,
    ref: s,
    props: [T, b],
    stateAttributesMapping: P
  });
  return /* @__PURE__ */ l(E.Provider, {
    value: _,
    children: k
  });
});
process.env.NODE_ENV !== "production" && (w.displayName = "ProgressRoot");
const I = /* @__PURE__ */ a.forwardRef(function(e, s) {
  const {
    render: u,
    className: m,
    ...i
  } = e, {
    state: n
  } = x();
  return N("div", e, {
    state: n,
    ref: s,
    props: i,
    stateAttributesMapping: P
  });
});
process.env.NODE_ENV !== "production" && (I.displayName = "ProgressTrack");
const M = /* @__PURE__ */ a.forwardRef(function(e, s) {
  const {
    render: u,
    className: m,
    ...i
  } = e, {
    max: n,
    min: o,
    value: t,
    state: d
  } = x(), c = Number.isFinite(t) && t !== null ? F(t, o, n) : null, f = a.useCallback(() => c == null ? {} : {
    insetInlineStart: 0,
    height: "inherit",
    width: `${c}%`
  }, [c]);
  return N("div", e, {
    state: d,
    ref: s,
    props: [{
      style: f()
    }, i],
    stateAttributesMapping: P
  });
});
process.env.NODE_ENV !== "production" && (M.displayName = "ProgressIndicator");
const A = /* @__PURE__ */ a.forwardRef(function(e, s) {
  const {
    className: u,
    render: m,
    children: i,
    ...n
  } = e, {
    value: o,
    formattedValue: t,
    state: d
  } = x(), c = o == null ? "indeterminate" : t, f = o == null ? null : t;
  return N("span", e, {
    state: d,
    ref: s,
    props: [{
      "aria-hidden": !0,
      children: typeof i == "function" ? i(c, o) : f
    }, n],
    stateAttributesMapping: P
  });
});
process.env.NODE_ENV !== "production" && (A.displayName = "ProgressValue");
const O = /* @__PURE__ */ a.forwardRef(function(e, s) {
  const {
    render: u,
    className: m,
    id: i,
    ...n
  } = e, {
    setLabelId: o,
    state: t
  } = x(), d = H(i, o);
  return N("span", e, {
    state: t,
    ref: s,
    props: [{
      id: d,
      role: "presentation"
    }, n],
    stateAttributesMapping: P
  });
});
process.env.NODE_ENV !== "production" && (O.displayName = "ProgressLabel");
function re({
  className: r,
  children: e,
  value: s,
  ...u
}) {
  return /* @__PURE__ */ y(
    w,
    {
      className: g("flex flex-wrap gap-3", r),
      "data-slot": "progress",
      value: s,
      ...u,
      children: [
        e,
        /* @__PURE__ */ l(z, { children: /* @__PURE__ */ l(G, {}) })
      ]
    }
  );
}
function z({ className: r, ...e }) {
  return /* @__PURE__ */ l(
    I,
    {
      className: g(
        "relative flex h-1.5 w-full items-center overflow-x-hidden rounded-full bg-muted",
        r
      ),
      "data-slot": "progress-track",
      ...e
    }
  );
}
function G({
  className: r,
  ...e
}) {
  return /* @__PURE__ */ l(
    M,
    {
      className: g("h-full bg-primary transition-all", r),
      "data-slot": "progress-indicator",
      ...e
    }
  );
}
function te({ className: r, ...e }) {
  return /* @__PURE__ */ l(
    O,
    {
      className: g("font-medium text-sm", r),
      "data-slot": "progress-label",
      ...e
    }
  );
}
function se({ className: r, ...e }) {
  return /* @__PURE__ */ l(
    A,
    {
      className: g(
        "ml-auto text-muted-foreground text-sm tabular-nums",
        r
      ),
      "data-slot": "progress-value",
      ...e
    }
  );
}
export {
  re as Progress,
  G as ProgressIndicator,
  te as ProgressLabel,
  z as ProgressTrack,
  se as ProgressValue
};
