import { jsx as m, jsxs as X } from "react/jsx-runtime";
import * as d from "react";
import { forwardRef as de, useId as ue } from "react";
import { c as G } from "./index-rKs9bXHr.mjs";
import { u as fe, c as E, a as me } from "./index-tyLV0iiH.mjs";
import { u as k } from "./index-DLcqcWxM.mjs";
import { c as pe } from "./index-DOfn3ixy.mjs";
import { u as Se } from "./index-ByaXH_ih.mjs";
import { u as he } from "./index-DPxjTK4w.mjs";
import { P as V } from "./index-CCNZ9uWB.mjs";
import { c as ge } from "./index-MiRhI3nq.mjs";
import { c as ve } from "./bind-CU-R61T-.mjs";
var W = ["PageUp", "PageDown"], q = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], J = {
  "from-left": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
  "from-right": ["Home", "PageDown", "ArrowDown", "ArrowRight"],
  "from-bottom": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
  "from-top": ["Home", "PageDown", "ArrowUp", "ArrowLeft"]
}, C = "Slider", [L, we, _e] = ge(C), [Q] = pe(C, [
  _e
]), [be, N] = Q(C), Z = d.forwardRef(
  (e, t) => {
    const {
      name: o,
      min: n = 0,
      max: i = 100,
      step: a = 1,
      orientation: r = "horizontal",
      disabled: c = !1,
      minStepsBetweenThumbs: l = 0,
      defaultValue: p = [n],
      value: w,
      onValueChange: s = () => {
      },
      onValueCommit: u = () => {
      },
      inverted: v = !1,
      form: y,
      ...g
    } = e, S = d.useRef(/* @__PURE__ */ new Set()), f = d.useRef(0), _ = r === "horizontal" ? ye : Re, [h = [], M] = fe({
      prop: w,
      defaultProp: p,
      onChange: (b) => {
        [...S.current][f.current]?.focus(), s(b);
      }
    }), B = d.useRef(h);
    function z(b) {
      const R = Ce(h, b);
      I(b, R);
    }
    function ce(b) {
      I(b, f.current);
    }
    function le() {
      const b = B.current[f.current];
      h[f.current] !== b && u(h);
    }
    function I(b, R, { commit: H } = { commit: !1 }) {
      const Y = ke(a), O = Ae(Math.round((b - n) / a) * a + n, Y), K = G(O, [n, i]);
      M((D = []) => {
        const x = De(D, K, R);
        if (Ke(x, l * a)) {
          f.current = x.indexOf(K);
          const j = String(x) !== String(D);
          return j && H && u(x), j ? x : D;
        } else
          return D;
      });
    }
    return /* @__PURE__ */ m(
      be,
      {
        scope: e.__scopeSlider,
        name: o,
        disabled: c,
        min: n,
        max: i,
        valueIndexToChangeRef: f,
        thumbs: S.current,
        values: h,
        orientation: r,
        form: y,
        children: /* @__PURE__ */ m(L.Provider, { scope: e.__scopeSlider, children: /* @__PURE__ */ m(L.Slot, { scope: e.__scopeSlider, children: /* @__PURE__ */ m(
          _,
          {
            "aria-disabled": c,
            "data-disabled": c ? "" : void 0,
            ...g,
            ref: t,
            onPointerDown: E(g.onPointerDown, () => {
              c || (B.current = h);
            }),
            min: n,
            max: i,
            inverted: v,
            onSlideStart: c ? void 0 : z,
            onSlideMove: c ? void 0 : ce,
            onSlideEnd: c ? void 0 : le,
            onHomeKeyDown: () => !c && I(n, 0, { commit: !0 }),
            onEndKeyDown: () => !c && I(i, h.length - 1, { commit: !0 }),
            onStepKeyDown: ({ event: b, direction: R }) => {
              if (!c) {
                const O = W.includes(b.key) || b.shiftKey && q.includes(b.key) ? 10 : 1, K = f.current, D = h[K], x = a * O * R;
                I(D + x, K, { commit: !0 });
              }
            }
          }
        ) }) })
      }
    );
  }
);
Z.displayName = C;
var [ee, te] = Q(C, {
  startEdge: "left",
  endEdge: "right",
  size: "width",
  direction: 1
}), ye = d.forwardRef(
  (e, t) => {
    const {
      min: o,
      max: n,
      dir: i,
      inverted: a,
      onSlideStart: r,
      onSlideMove: c,
      onSlideEnd: l,
      onStepKeyDown: p,
      ...w
    } = e, [s, u] = d.useState(null), v = k(t, (_) => u(_)), y = d.useRef(void 0), g = Se(i), S = g === "ltr", f = S && !a || !S && a;
    function P(_) {
      const h = y.current || s.getBoundingClientRect(), M = [0, h.width], z = U(M, f ? [o, n] : [n, o]);
      return y.current = h, z(_ - h.left);
    }
    return /* @__PURE__ */ m(
      ee,
      {
        scope: e.__scopeSlider,
        startEdge: f ? "left" : "right",
        endEdge: f ? "right" : "left",
        direction: f ? 1 : -1,
        size: "width",
        children: /* @__PURE__ */ m(
          ne,
          {
            dir: g,
            "data-orientation": "horizontal",
            ...w,
            ref: v,
            style: {
              ...w.style,
              "--radix-slider-thumb-transform": "translateX(-50%)"
            },
            onSlideStart: (_) => {
              const h = P(_.clientX);
              r?.(h);
            },
            onSlideMove: (_) => {
              const h = P(_.clientX);
              c?.(h);
            },
            onSlideEnd: () => {
              y.current = void 0, l?.();
            },
            onStepKeyDown: (_) => {
              const M = J[f ? "from-left" : "from-right"].includes(_.key);
              p?.({ event: _, direction: M ? -1 : 1 });
            }
          }
        )
      }
    );
  }
), Re = d.forwardRef(
  (e, t) => {
    const {
      min: o,
      max: n,
      inverted: i,
      onSlideStart: a,
      onSlideMove: r,
      onSlideEnd: c,
      onStepKeyDown: l,
      ...p
    } = e, w = d.useRef(null), s = k(t, w), u = d.useRef(void 0), v = !i;
    function y(g) {
      const S = u.current || w.current.getBoundingClientRect(), f = [0, S.height], _ = U(f, v ? [n, o] : [o, n]);
      return u.current = S, _(g - S.top);
    }
    return /* @__PURE__ */ m(
      ee,
      {
        scope: e.__scopeSlider,
        startEdge: v ? "bottom" : "top",
        endEdge: v ? "top" : "bottom",
        size: "height",
        direction: v ? 1 : -1,
        children: /* @__PURE__ */ m(
          ne,
          {
            "data-orientation": "vertical",
            ...p,
            ref: s,
            style: {
              ...p.style,
              "--radix-slider-thumb-transform": "translateY(50%)"
            },
            onSlideStart: (g) => {
              const S = y(g.clientY);
              a?.(S);
            },
            onSlideMove: (g) => {
              const S = y(g.clientY);
              r?.(S);
            },
            onSlideEnd: () => {
              u.current = void 0, c?.();
            },
            onStepKeyDown: (g) => {
              const f = J[v ? "from-bottom" : "from-top"].includes(g.key);
              l?.({ event: g, direction: f ? -1 : 1 });
            }
          }
        )
      }
    );
  }
), ne = d.forwardRef(
  (e, t) => {
    const {
      __scopeSlider: o,
      onSlideStart: n,
      onSlideMove: i,
      onSlideEnd: a,
      onHomeKeyDown: r,
      onEndKeyDown: c,
      onStepKeyDown: l,
      ...p
    } = e, w = N(C, o);
    return /* @__PURE__ */ m(
      V.span,
      {
        ...p,
        ref: t,
        onKeyDown: E(e.onKeyDown, (s) => {
          s.key === "Home" ? (r(s), s.preventDefault()) : s.key === "End" ? (c(s), s.preventDefault()) : W.concat(q).includes(s.key) && (l(s), s.preventDefault());
        }),
        onPointerDown: E(e.onPointerDown, (s) => {
          const u = s.target;
          u.setPointerCapture(s.pointerId), s.preventDefault(), w.thumbs.has(u) ? u.focus() : n(s);
        }),
        onPointerMove: E(e.onPointerMove, (s) => {
          s.target.hasPointerCapture(s.pointerId) && i(s);
        }),
        onPointerUp: E(e.onPointerUp, (s) => {
          const u = s.target;
          u.hasPointerCapture(s.pointerId) && (u.releasePointerCapture(s.pointerId), a(s));
        })
      }
    );
  }
), oe = "SliderTrack", re = d.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, ...n } = e, i = N(oe, o);
    return /* @__PURE__ */ m(
      V.span,
      {
        "data-disabled": i.disabled ? "" : void 0,
        "data-orientation": i.orientation,
        ...n,
        ref: t
      }
    );
  }
);
re.displayName = oe;
var $ = "SliderRange", ie = d.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, ...n } = e, i = N($, o), a = te($, o), r = d.useRef(null), c = k(t, r), l = i.values.length, p = i.values.map(
      (u) => ae(u, i.min, i.max)
    ), w = l > 1 ? Math.min(...p) : 0, s = 100 - Math.max(...p);
    return /* @__PURE__ */ m(
      V.span,
      {
        "data-orientation": i.orientation,
        "data-disabled": i.disabled ? "" : void 0,
        ...n,
        ref: c,
        style: {
          ...e.style,
          [a.startEdge]: w + "%",
          [a.endEdge]: s + "%"
        }
      }
    );
  }
);
ie.displayName = $;
var F = "SliderThumb", se = d.forwardRef(
  (e, t) => {
    const o = we(e.__scopeSlider), [n, i] = d.useState(null), a = k(t, (c) => i(c)), r = d.useMemo(
      () => n ? o().findIndex((c) => c.ref.current === n) : -1,
      [o, n]
    );
    return /* @__PURE__ */ m(xe, { ...e, ref: a, index: r });
  }
), xe = d.forwardRef(
  (e, t) => {
    const { __scopeSlider: o, index: n, name: i, ...a } = e, r = N(F, o), c = te(F, o), [l, p] = d.useState(null), w = k(t, (P) => p(P)), s = l ? r.form || !!l.closest("form") : !0, u = he(l), v = r.values[n], y = v === void 0 ? 0 : ae(v, r.min, r.max), g = Ee(n, r.values.length), S = u?.[c.size], f = S ? Me(S, y, c.direction) : 0;
    return d.useEffect(() => {
      if (l)
        return r.thumbs.add(l), () => {
          r.thumbs.delete(l);
        };
    }, [l, r.thumbs]), /* @__PURE__ */ X(
      "span",
      {
        style: {
          transform: "var(--radix-slider-thumb-transform)",
          position: "absolute",
          [c.startEdge]: `calc(${y}% + ${f}px)`
        },
        children: [
          /* @__PURE__ */ m(L.ItemSlot, { scope: e.__scopeSlider, children: /* @__PURE__ */ m(
            V.span,
            {
              role: "slider",
              "aria-label": e["aria-label"] || g,
              "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,
              ...a,
              ref: w,
              style: v === void 0 ? { display: "none" } : e.style,
              onFocus: E(e.onFocus, () => {
                r.valueIndexToChangeRef.current = n;
              })
            }
          ) }),
          s && /* @__PURE__ */ m(
            Pe,
            {
              name: i ?? (r.name ? r.name + (r.values.length > 1 ? "[]" : "") : void 0),
              form: r.form,
              value: v
            },
            n
          )
        ]
      }
    );
  }
);
se.displayName = F;
var Pe = (e) => {
  const { value: t, ...o } = e, n = d.useRef(null), i = me(t);
  return d.useEffect(() => {
    const a = n.current, r = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(r, "value").set;
    if (i !== t && l) {
      const p = new Event("input", { bubbles: !0 });
      l.call(a, t), a.dispatchEvent(p);
    }
  }, [i, t]), /* @__PURE__ */ m("input", { style: { display: "none" }, ...o, ref: n, defaultValue: t });
};
function De(e = [], t, o) {
  const n = [...e];
  return n[o] = t, n.sort((i, a) => i - a);
}
function ae(e, t, o) {
  const a = 100 / (o - t) * (e - t);
  return G(a, [0, 100]);
}
function Ee(e, t) {
  return t > 2 ? `Value ${e + 1} of ${t}` : t === 2 ? ["Minimum", "Maximum"][e] : void 0;
}
function Ce(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 Me(e, t, o) {
  const n = e / 2, a = U([0, 50], [0, n]);
  return (n - a(t) * o) * o;
}
function Ie(e) {
  return e.slice(0, -1).map((t, o) => e[o + 1] - t);
}
function Ke(e, t) {
  if (t > 0) {
    const o = Ie(e);
    return Math.min(...o) >= t;
  }
  return !0;
}
function U(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 ke(e) {
  return (String(e).split(".")[1] || "").length;
}
function Ae(e, t) {
  const o = Math.pow(10, t);
  return Math.round(e * o) / o;
}
var Te = Z, Ve = re, Ne = ie, Be = se;
const ze = {
  "purpur-slider": "_purpur-slider_14tuk_1",
  "purpur-slider__track": "_purpur-slider__track_14tuk_17",
  "purpur-slider__range": "_purpur-slider__range_14tuk_17",
  "purpur-slider__thumb": "_purpur-slider__thumb_14tuk_43"
}, A = ve.bind(ze), Ze = ["horizontal", "vertical"], T = "purpur-slider", He = (e) => String(e), Oe = ({
  "aria-label": e,
  "aria-valuetext": t,
  className: o,
  defaultValue: n,
  id: i,
  value: a,
  ...r
}, c) => {
  const l = ue(), p = a || n;
  return /* @__PURE__ */ X(
    Te,
    {
      ...r,
      id: i || l,
      ref: c,
      className: A(T, o),
      value: a,
      defaultValue: n,
      children: [
        /* @__PURE__ */ m(Ve, { className: A(`${T}__track`), children: /* @__PURE__ */ m(Ne, { className: A(`${T}__range`) }) }),
        p?.map((w, s) => /* @__PURE__ */ m(
          Be,
          {
            className: A(`${T}__thumb`),
            "aria-label": e,
            "aria-valuetext": t
          },
          He(s)
        ))
      ]
    }
  );
}, Le = de(Oe);
Le.displayName = "Slider";
export {
  Ze as S,
  Le as a
};
//# sourceMappingURL=slider-CDOrFmK-.mjs.map
