"use client";
import * as u from "react";
import { clamp as $ } from "../../../../../@radix-ui_number@1.1.0/node_modules/@radix-ui/number/dist/index.js";
import { composeEventHandlers as _ } from "../../../../../@radix-ui_primitive@1.1.1/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as K } from "../../../../../@radix-ui_react-compose-refs@1.1.1_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as ae } from "../../../../../@radix-ui_react-context@1.1.1_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-context/dist/index.js";
import { useControllableState as ce } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { useDirection as le } from "../../../../../@radix-ui_react-direction@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-direction/dist/index.js";
import { usePrevious as de } from "../../../../../@radix-ui_react-use-previous@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-use-previous/dist/index.js";
import { useSize as ue } from "../../../../../@radix-ui_react-use-size@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-use-size/dist/index.js";
import { Primitive as T } from "../../../../../@radix-ui_react-primitive@2.0.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@19_i7clg2yux7aeir464mbcqjzvuu/node_modules/@radix-ui/react-primitive/dist/index.js";
import { createCollection as fe } from "../../../../../@radix-ui_react-collection@1.1.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@1_wmq6ikgmvt5xnaxokuj5xkr5am/node_modules/@radix-ui/react-collection/dist/index.js";
import { jsx as g, jsxs as me } from "react/jsx-runtime";
var j = ["PageUp", "PageDown"], X = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], G = {
  "from-left": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
  "from-right": ["Home", "PageDown", "ArrowDown", "ArrowRight"],
  "from-bottom": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
  "from-top": ["Home", "PageDown", "ArrowUp", "ArrowLeft"]
}, M = "Slider", [N, pe, he] = fe(M), [W, Oe] = ae(M, [
  he
]), [Se, B] = W(M), q = u.forwardRef(
  (e, t) => {
    const {
      name: o,
      min: n = 0,
      max: i = 100,
      step: c = 1,
      orientation: r = "horizontal",
      disabled: a = !1,
      minStepsBetweenThumbs: l = 0,
      defaultValue: m = [n],
      value: P,
      onValueChange: s = () => {
      },
      onValueCommit: d = () => {
      },
      inverted: v = !1,
      form: R,
      ...S
    } = e, p = u.useRef(/* @__PURE__ */ new Set()), f = u.useRef(0), w = r === "horizontal" ? ge : ve, [h = [], A] = ce({
      prop: P,
      defaultProp: m,
      onChange: (b) => {
        var E;
        (E = [...p.current][f.current]) == null || E.focus(), s(b);
      }
    }), k = u.useRef(h);
    function H(b) {
      const x = xe(h, b);
      I(b, x);
    }
    function ie(b) {
      I(b, f.current);
    }
    function se() {
      const b = k.current[f.current];
      h[f.current] !== b && d(h);
    }
    function I(b, x, { commit: E } = { commit: !1 }) {
      const U = Ce(c), z = _e(Math.round((b - n) / c) * c + n, U), V = $(z, [n, i]);
      A((C = []) => {
        const y = Pe(C, V, x);
        if (Ee(y, l * c)) {
          f.current = y.indexOf(V);
          const Y = String(y) !== String(C);
          return Y && E && d(y), Y ? y : C;
        } else
          return C;
      });
    }
    return /* @__PURE__ */ g(
      Se,
      {
        scope: e.__scopeSlider,
        name: o,
        disabled: a,
        min: n,
        max: i,
        valueIndexToChangeRef: f,
        thumbs: p.current,
        values: h,
        orientation: r,
        form: R,
        children: /* @__PURE__ */ g(N.Provider, { scope: e.__scopeSlider, children: /* @__PURE__ */ g(N.Slot, { scope: e.__scopeSlider, children: /* @__PURE__ */ g(
          w,
          {
            "aria-disabled": a,
            "data-disabled": a ? "" : void 0,
            ...S,
            ref: t,
            onPointerDown: _(S.onPointerDown, () => {
              a || (k.current = h);
            }),
            min: n,
            max: i,
            inverted: v,
            onSlideStart: a ? void 0 : H,
            onSlideMove: a ? void 0 : ie,
            onSlideEnd: a ? void 0 : se,
            onHomeKeyDown: () => !a && I(n, 0, { commit: !0 }),
            onEndKeyDown: () => !a && I(i, h.length - 1, { commit: !0 }),
            onStepKeyDown: ({ event: b, direction: x }) => {
              if (!a) {
                const z = j.includes(b.key) || b.shiftKey && X.includes(b.key) ? 10 : 1, V = f.current, C = h[V], y = c * z * x;
                I(C + y, V, { commit: !0 });
              }
            }
          }
        ) }) })
      }
    );
  }
);
q.displayName = M;
var [J, Q] = W(M, {
  startEdge: "left",
  endEdge: "right",
  size: "width",
  direction: 1
}), ge = u.forwardRef(
  (e, t) => {
    const {
      min: o,
      max: n,
      dir: i,
      inverted: c,
      onSlideStart: r,
      onSlideMove: a,
      onSlideEnd: l,
      onStepKeyDown: m,
      ...P
    } = e, [s, d] = u.useState(null), v = K(t, (w) => d(w)), R = u.useRef(void 0), S = le(i), p = S === "ltr", f = p && !c || !p && c;
    function D(w) {
      const h = R.current || s.getBoundingClientRect(), A = [0, h.width], H = F(A, f ? [o, n] : [n, o]);
      return R.current = h, H(w - h.left);
    }
    return /* @__PURE__ */ g(
      J,
      {
        scope: e.__scopeSlider,
        startEdge: f ? "left" : "right",
        endEdge: f ? "right" : "left",
        direction: f ? 1 : -1,
        size: "width",
        children: /* @__PURE__ */ g(
          Z,
          {
            dir: S,
            "data-orientation": "horizontal",
            ...P,
            ref: v,
            style: {
              ...P.style,
              "--radix-slider-thumb-transform": "translateX(-50%)"
            },
            onSlideStart: (w) => {
              const h = D(w.clientX);
              r == null || r(h);
            },
            onSlideMove: (w) => {
              const h = D(w.clientX);
              a == null || a(h);
            },
            onSlideEnd: () => {
              R.current = void 0, l == null || l();
            },
            onStepKeyDown: (w) => {
              const A = G[f ? "from-left" : "from-right"].includes(w.key);
              m == null || m({ event: w, direction: A ? -1 : 1 });
            }
          }
        )
      }
    );
  }
), ve = u.forwardRef(
  (e, t) => {
    const {
      min: o,
      max: n,
      inverted: i,
      onSlideStart: c,
      onSlideMove: r,
      onSlideEnd: a,
      onStepKeyDown: l,
      ...m
    } = e, P = u.useRef(null), s = K(t, P), d = u.useRef(void 0), v = !i;
    function R(S) {
      const p = d.current || P.current.getBoundingClientRect(), f = [0, p.height], w = F(f, v ? [n, o] : [o, n]);
      return d.current = p, w(S - p.top);
    }
    return /* @__PURE__ */ g(
      J,
      {
        scope: e.__scopeSlider,
        startEdge: v ? "bottom" : "top",
        endEdge: v ? "top" : "bottom",
        size: "height",
        direction: v ? 1 : -1,
        children: /* @__PURE__ */ g(
          Z,
          {
            "data-orientation": "vertical",
            ...m,
            ref: s,
            style: {
              ...m.style,
              "--radix-slider-thumb-transform": "translateY(50%)"
            },
            onSlideStart: (S) => {
              const p = R(S.clientY);
              c == null || c(p);
            },
            onSlideMove: (S) => {
              const p = R(S.clientY);
              r == null || r(p);
            },
            onSlideEnd: () => {
              d.current = void 0, a == null || a();
            },
            onStepKeyDown: (S) => {
              const f = G[v ? "from-bottom" : "from-top"].includes(S.key);
              l == null || l({ event: S, direction: f ? -1 : 1 });
            }
          }
        )
      }
    );
  }
), Z = u.forwardRef(
  (e, t) => {
    const {
      __scopeSlider: o,
      onSlideStart: n,
      onSlideMove: i,
      onSlideEnd: c,
      onHomeKeyDown: r,
      onEndKeyDown: a,
      onStepKeyDown: l,
      ...m
    } = e, P = B(M, o);
    return /* @__PURE__ */ g(
      T.span,
      {
        ...m,
        ref: t,
        onKeyDown: _(e.onKeyDown, (s) => {
          s.key === "Home" ? (r(s), s.preventDefault()) : s.key === "End" ? (a(s), s.preventDefault()) : j.concat(X).includes(s.key) && (l(s), s.preventDefault());
        }),
        onPointerDown: _(e.onPointerDown, (s) => {
          const d = s.target;
          d.setPointerCapture(s.pointerId), s.preventDefault(), P.thumbs.has(d) ? d.focus() : n(s);
        }),
        onPointerMove: _(e.onPointerMove, (s) => {
          s.target.hasPointerCapture(s.pointerId) && i(s);
        }),
        onPointerUp: _(e.onPointerUp, (s) => {
          const d = s.target;
          d.hasPointerCapture(s.pointerId) && (d.releasePointerCapture(s.pointerId), c(s));
        })
      }
    );
  }
), ee = "SliderTrack", te = u.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, ...n } = e, i = B(ee, o);
    return /* @__PURE__ */ g(
      T.span,
      {
        "data-disabled": i.disabled ? "" : void 0,
        "data-orientation": i.orientation,
        ...n,
        ref: t
      }
    );
  }
);
te.displayName = ee;
var O = "SliderRange", ne = u.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, ...n } = e, i = B(O, o), c = Q(O, o), r = u.useRef(null), a = K(t, r), l = i.values.length, m = i.values.map(
      (d) => re(d, i.min, i.max)
    ), P = l > 1 ? Math.min(...m) : 0, s = 100 - Math.max(...m);
    return /* @__PURE__ */ g(
      T.span,
      {
        "data-orientation": i.orientation,
        "data-disabled": i.disabled ? "" : void 0,
        ...n,
        ref: a,
        style: {
          ...e.style,
          [c.startEdge]: P + "%",
          [c.endEdge]: s + "%"
        }
      }
    );
  }
);
ne.displayName = O;
var L = "SliderThumb", oe = u.forwardRef(
  (e, t) => {
    const o = pe(e.__scopeSlider), [n, i] = u.useState(null), c = K(t, (a) => i(a)), r = u.useMemo(
      () => n ? o().findIndex((a) => a.ref.current === n) : -1,
      [o, n]
    );
    return /* @__PURE__ */ g(we, { ...e, ref: c, index: r });
  }
), we = u.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, index: n, name: i, ...c } = e, r = B(L, o), a = Q(L, o), [l, m] = u.useState(null), P = K(t, (D) => m(D)), s = l ? r.form || !!l.closest("form") : !0, d = ue(l), v = r.values[n], R = v === void 0 ? 0 : re(v, r.min, r.max), S = Re(n, r.values.length), p = d == null ? void 0 : d[a.size], f = p ? ye(p, R, a.direction) : 0;
    return u.useEffect(() => {
      if (l)
        return r.thumbs.add(l), () => {
          r.thumbs.delete(l);
        };
    }, [l, r.thumbs]), /* @__PURE__ */ me(
      "span",
      {
        style: {
          transform: "var(--radix-slider-thumb-transform)",
          position: "absolute",
          [a.startEdge]: `calc(${R}% + ${f}px)`
        },
        children: [
          /* @__PURE__ */ g(N.ItemSlot, { scope: e.__scopeSlider, children: /* @__PURE__ */ g(
            T.span,
            {
              role: "slider",
              "aria-label": e["aria-label"] || S,
              "aria-valuemin": r.min,
              "aria-valuenow": v,
              "aria-valuemax": r.max,
              "aria-orientation": r.orientation,
              "data-orientation": r.orientation,
              "data-disabled": r.disabled ? "" : void 0,
              tabIndex: r.disabled ? void 0 : 0,
              ...c,
              ref: P,
              style: v === void 0 ? { display: "none" } : e.style,
              onFocus: _(e.onFocus, () => {
                r.valueIndexToChangeRef.current = n;
              })
            }
          ) }),
          s && /* @__PURE__ */ g(
            be,
            {
              name: i ?? (r.name ? r.name + (r.values.length > 1 ? "[]" : "") : void 0),
              form: r.form,
              value: v
            },
            n
          )
        ]
      }
    );
  }
);
oe.displayName = L;
var be = (e) => {
  const { value: t, ...o } = e, n = u.useRef(null), i = de(t);
  return u.useEffect(() => {
    const c = n.current, r = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(r, "value").set;
    if (i !== t && l) {
      const m = new Event("input", { bubbles: !0 });
      l.call(c, t), c.dispatchEvent(m);
    }
  }, [i, t]), /* @__PURE__ */ g("input", { style: { display: "none" }, ...o, ref: n, defaultValue: t });
};
function Pe(e = [], t, o) {
  const n = [...e];
  return n[o] = t, n.sort((i, c) => i - c);
}
function re(e, t, o) {
  const c = 100 / (o - t) * (e - t);
  return $(c, [0, 100]);
}
function Re(e, t) {
  return t > 2 ? `Value ${e + 1} of ${t}` : t === 2 ? ["Minimum", "Maximum"][e] : void 0;
}
function xe(e, t) {
  if (e.length === 1) return 0;
  const o = e.map((i) => Math.abs(i - t)), n = Math.min(...o);
  return o.indexOf(n);
}
function ye(e, t, o) {
  const n = e / 2, c = F([0, 50], [0, n]);
  return (n - c(t) * o) * o;
}
function De(e) {
  return e.slice(0, -1).map((t, o) => e[o + 1] - t);
}
function Ee(e, t) {
  if (t > 0) {
    const o = De(e);
    return Math.min(...o) >= t;
  }
  return !0;
}
function F(e, t) {
  return (o) => {
    if (e[0] === e[1] || t[0] === t[1]) return t[0];
    const n = (t[1] - t[0]) / (e[1] - e[0]);
    return t[0] + n * (o - e[0]);
  };
}
function Ce(e) {
  return (String(e).split(".")[1] || "").length;
}
function _e(e, t) {
  const o = Math.pow(10, t);
  return Math.round(e * o) / o;
}
var Le = q, Fe = te, Ue = ne, Ye = oe;
export {
  Ue as Range,
  Le as Root,
  q as Slider,
  ne as SliderRange,
  oe as SliderThumb,
  te as SliderTrack,
  Ye as Thumb,
  Fe as Track,
  Oe as createSliderScope
};
//# sourceMappingURL=index.js.map
