import { o as Bt } from "./rolldown-runtime.js";
import { i as Ot, n as $t, t as zt } from "./vendor/react.js";
import { f as Ye } from "./safeReact.js";
import { l as Dt, o as Ht, s as qt, t as Le } from "./useRenderElement.js";
import { n as K, t as He } from "./useIsoLayoutEffect.js";
import { t as se } from "./utils.js";
import { n as Wt } from "./useAnimationFrame.js";
import { t as Ge } from "./useBaseUiId.js";
import { n as ot, r as Ut, t as it } from "./shadowDom.js";
import { c as Kt } from "./element.js";
import { t as Ve } from "./owner.js";
import { t as Xt } from "./CSPContext.js";
import { n as st, t as Yt } from "./DirectionContext.js";
import { t as ne } from "./clamp.js";
import { t as Gt } from "./addEventListener.js";
import { b as et, m as Zt, n as at, o as Jt, t as Me, u as Qt } from "./createBaseUIEventDetails.js";
import { t as lt } from "./useValueAsRef.js";
import { t as tt } from "./visuallyHidden.js";
import { t as er } from "./useControlled.js";
import { n as tr } from "./useCompositeListItem.js";
import { t as rr } from "./CompositeList.js";
import { a as ct, c as ut, f as dt, i as ft, n as mt, o as ht, p as pt, s as nr } from "./composite2.js";
import { t as or } from "./label.js";
import { t as ir } from "./FieldTooltip.js";
import { n as sr, t as ar } from "./field-props.js";
import { a as bt, c as lr, r as cr, t as ur } from "./useRegisterFieldControl.js";
import { t as dr } from "./FormContext.js";
import { t as fr } from "./useLabelableId.js";
import { a as mr, c as hr, i as pr, l as br, n as gr, o as vr, r as yr, s as xr, t as Rr } from "./Field.js";
import { t as gt } from "./useIsHydrating.js";
import { t as wr } from "./useValueChanged.js";
import { n as Cr, t as Pr } from "./resolveAriaLabelledBy.js";
import { n as qe, t as Ze } from "./valueToPercent.js";
var a = /* @__PURE__ */ Bt(Ot()), u = zt(), vt = function(t) {
  const { direction: r = "ltr" } = t, o = a.useMemo(() => ({ direction: r }), [r]);
  return /* @__PURE__ */ (0, u.jsx)(Yt.Provider, {
    value: o,
    children: t.children
  });
};
function yt(e, t, r = (o, n) => o === n) {
  return e.length === t.length && e.every((o, n) => r(o, t[n]));
}
function xt(e, t) {
  return e - t;
}
function Ir(e, t, r) {
  const o = e.slice();
  return o[t] = r, o.sort(xt);
}
function Rt(e, t, r, o, n, c) {
  let s = e;
  return s = ne(s, r, o), n && (s = Ir(c, t, ne(s, c[t - 1] || -1 / 0, c[t + 1] || 1 / 0))), s;
}
function wt(e, t, r) {
  if (!Array.isArray(e)) return !0;
  const o = e.reduce((n, c, s, f) => (s === f.length - 1 || n.push(Math.abs(c - f[s + 1])), n), []);
  return Math.min(...o) >= t * r;
}
var Be = {
  activeThumbIndex: () => null,
  max: () => null,
  min: () => null,
  minStepsBetweenValues: () => null,
  step: () => null,
  values: () => null,
  ...lr
}, Ct = /* @__PURE__ */ a.createContext(void 0);
function We() {
  const e = a.useContext(Ct);
  if (e === void 0) throw new Error(qt(62));
  return e;
}
function Sr(e) {
  return "key" in e ? Zt : Qt;
}
function Nr(e, t) {
  return typeof e == "number" && typeof t == "number" ? e === t : Array.isArray(e) && Array.isArray(t) ? yt(e, t) : !1;
}
var Pt = /* @__PURE__ */ a.forwardRef(function(t, r) {
  const { "aria-labelledby": o, className: n, defaultValue: c, disabled: s = !1, id: f, format: d, largeStep: m = 10, locale: v, render: S, max: i = 100, min: h = 0, minStepsBetweenValues: R = 0, form: w, name: N, onValueChange: D, onValueCommitted: H, orientation: B = "horizontal", step: O = 1, thumbCollisionBehavior: ae = "push", thumbAlignment: X = "center", value: Y, style: $, ...Z } = t, G = Ge(f), F = Pr(G), z = K(D), x = K(H), { clearErrors: y } = dr(), { state: J, disabled: q, name: ee, setTouched: E, setDirty: k, validityData: Ne, shouldValidateOnChange: le, validation: te } = bt(), { labelId: ce } = cr(), [ue, Ce] = a.useState(), de = o ?? Cr(ce, ue), W = q || s, Q = ee ?? N, [M, be] = er({
    controlled: Y,
    default: c ?? h,
    name: "Slider"
  }), U = a.useRef(null), j = a.useRef(null), ge = a.useRef([]), l = a.useRef(null), p = a.useRef(null), b = a.useRef(-1), C = a.useRef(null), A = a.useRef(null), _ = a.useRef("none"), ve = lt(d), [L, re] = a.useState(-1), [ye, Ae] = a.useState(-1), [xe, Re] = a.useState(!1), [Te, fe] = a.useState(() => /* @__PURE__ */ new Map()), [I, me] = a.useState([void 0, void 0]), oe = K((T) => {
    re(T), T !== -1 && Ae(T);
  });
  ur(j, {
    id: G,
    value: M
  }), wr(M, () => {
    y(Q), le() ? te.commit(M) : te.commit(M, !0);
    const T = Ne.initialValue;
    let pe;
    Array.isArray(M) && Array.isArray(T) ? pe = !yt(M, T) : pe = M !== T, k(pe);
  });
  const we = K((T) => {
    T && (j.current = T);
  }), Pe = Array.isArray(M), Ie = a.useMemo(() => Pe ? M.slice().sort(xt) : [ne(M, h, i)], [
    i,
    h,
    Pe,
    M
  ]), Se = K((T, pe) => {
    if (Number.isNaN(T) || Nr(T, M)) return;
    const ie = pe ?? Me("none", void 0, void 0, { activeThumbIndex: -1 });
    _.current = ie.reason;
    const g = ie.event, P = new (g.constructor ?? Event)(g.type, g);
    Object.defineProperty(P, "target", {
      writable: !0,
      value: {
        value: T,
        name: Q
      }
    }), ie.event = P, A.current = T, z(T, ie), !ie.isCanceled && be(T);
  }), je = K((T, pe, ie) => {
    const g = Rt(T, pe, h, i, Pe, Ie);
    if (wt(g, O, R)) {
      const P = Sr(ie);
      Se(g, Me(P, ie.nativeEvent, void 0, { activeThumbIndex: pe })), E(!0), x(A.current ?? g, at(P, ie.nativeEvent));
    }
  });
  He(() => {
    const T = it(Ve(U.current));
    W && ot(U.current, T) && T.blur();
  }, [W]), W && L !== -1 && oe(-1);
  const he = a.useMemo(() => ({
    ...J,
    activeThumbIndex: L,
    disabled: W,
    dragging: xe,
    orientation: B,
    max: i,
    min: h,
    minStepsBetweenValues: R,
    step: O,
    values: Ie
  }), [
    J,
    L,
    W,
    xe,
    i,
    h,
    R,
    B,
    O,
    Ie
  ]), Ue = a.useMemo(() => ({
    active: L,
    controlRef: j,
    disabled: W,
    dragging: xe,
    validation: te,
    formatOptionsRef: ve,
    handleInputChange: je,
    indicatorPosition: I,
    inset: X !== "center",
    labelId: de,
    rootLabelId: F,
    largeStep: m,
    lastUsedThumbIndex: ye,
    lastChangedValueRef: A,
    lastChangeReasonRef: _,
    form: w,
    locale: v,
    max: i,
    min: h,
    minStepsBetweenValues: R,
    name: Q,
    onValueCommitted: x,
    orientation: B,
    pressedInputRef: l,
    pressedThumbCenterOffsetRef: p,
    pressedThumbIndexRef: b,
    pressedValuesRef: C,
    registerFieldControlRef: we,
    renderBeforeHydration: X === "edge",
    setActive: oe,
    setDragging: Re,
    setIndicatorPosition: me,
    setLabelId: Ce,
    setValue: Se,
    state: he,
    step: O,
    thumbCollisionBehavior: ae,
    thumbMap: Te,
    thumbRefs: ge,
    values: Ie
  }), [
    L,
    j,
    de,
    F,
    W,
    xe,
    te,
    ve,
    je,
    I,
    m,
    ye,
    A,
    _,
    w,
    v,
    i,
    h,
    R,
    Q,
    x,
    B,
    l,
    p,
    b,
    C,
    we,
    oe,
    Re,
    me,
    Ce,
    Se,
    he,
    O,
    ae,
    X,
    Te,
    ge,
    Ie
  ]), Oe = Le("div", t, {
    state: he,
    ref: [r, U],
    props: [
      {
        "aria-labelledby": de,
        id: G,
        role: "group"
      },
      te.getValidationProps,
      Z
    ],
    stateAttributesMapping: Be
  });
  return /* @__PURE__ */ (0, u.jsx)(Ct.Provider, {
    value: Ue,
    children: /* @__PURE__ */ (0, u.jsx)(rr, {
      elementsRef: ge,
      onMapChange: fe,
      children: Oe
    })
  });
});
function It(e) {
  const t = e.getBoundingClientRect();
  return {
    x: (t.left + t.right) / 2,
    y: (t.top + t.bottom) / 2
  };
}
function ke(e) {
  if (e === 0) return 0;
  if (Math.abs(e) < 1) {
    const r = e.toExponential().split("e-"), o = r[0].split(".")[1];
    return (o ? o.length : 0) + parseInt(r[1], 10);
  }
  const t = e.toString().split(".")[1];
  return t ? t.length : 0;
}
function St(e, t, r) {
  const o = Math.round((e - r) / t) * t + r;
  return Number(o.toFixed(Math.max(ke(t), ke(r))));
}
function rt({ values: e, index: t, nextValue: r, min: o, max: n, step: c, minStepsBetweenValues: s, initialValues: f }) {
  if (e.length === 0) return [];
  const d = e.slice(), m = c * s, v = d.length - 1, S = f ?? e;
  d[t] = ne(r, o + t * m, n - (v - t) * m);
  for (let i = t + 1; i <= v; i += 1) {
    const h = d[i - 1] + m, R = n - (v - i) * m, w = S[i] ?? d[i];
    let N = Math.max(d[i], h);
    w < N && (N = Math.max(w, h)), d[i] = ne(N, h, R);
  }
  for (let i = t - 1; i >= 0; i -= 1) {
    const h = d[i + 1] - m, R = o + i * m, w = S[i] ?? d[i];
    let N = Math.min(d[i], h);
    w > N && (N = Math.min(w, h)), d[i] = ne(N, R, h);
  }
  for (let i = 0; i <= v; i += 1) d[i] = Number(d[i].toFixed(12));
  return d;
}
function Ar({ behavior: e, values: t, currentValues: r, initialValues: o, pressedIndex: n, nextValue: c, min: s, max: f, step: d, minStepsBetweenValues: m }) {
  const v = r ?? t, S = o ?? t;
  if (!(v.length > 1)) return {
    value: c,
    thumbIndex: 0,
    didSwap: !1
  };
  const i = d * m;
  switch (e) {
    case "swap": {
      const h = v[n], R = 1e-7, w = v.slice(), N = w[n - 1], D = w[n + 1], H = ne(c, N != null ? N + i : s, D != null ? D - i : f), B = Number(H.toFixed(12));
      w[n] = B;
      const O = c > h, ae = c < h, X = O && D != null && c >= D - R, Y = ae && N != null && c <= N + R;
      if (!X && !Y) return {
        value: w,
        thumbIndex: n,
        didSwap: !1
      };
      const $ = X ? n + 1 : n - 1, Z = w.map((x, y) => {
        if (y === n) return B;
        const J = S[y];
        return J ?? v[y];
      });
      let G = c;
      X ? G = Math.max(c, w[$]) : G = Math.min(c, w[$]);
      const F = rt({
        values: w,
        index: $,
        nextValue: G,
        min: s,
        max: f,
        step: d,
        minStepsBetweenValues: m,
        initialValues: Z
      }), z = X ? $ - 1 : $ + 1;
      if (z >= 0 && z < F.length) {
        const x = F[z - 1], y = F[z + 1];
        let J = x != null ? x + i : s;
        J = Math.max(J, s + z * i);
        let q = y != null ? y - i : f;
        q = Math.min(q, f - (F.length - 1 - z) * i);
        const ee = ne(B, J, q);
        F[z] = Number(ee.toFixed(12));
      }
      return {
        value: F,
        thumbIndex: $,
        didSwap: !0
      };
    }
    case "push":
      return {
        value: rt({
          values: v,
          index: n,
          nextValue: c,
          min: s,
          max: f,
          step: d,
          minStepsBetweenValues: m
        }),
        thumbIndex: n,
        didSwap: !1
      };
    default: {
      const h = v.slice(), R = h[n - 1], w = h[n + 1], N = ne(c, R != null ? R + i : s, w != null ? w - i : f);
      return h[n] = Number(N.toFixed(12)), {
        value: h,
        thumbIndex: n,
        didSwap: !1
      };
    }
  }
}
var Tr = 2;
function Er(e, t) {
  if (!e) return {
    start: 0,
    end: 0
  };
  function r(c) {
    const s = c != null ? parseFloat(c) : 0;
    return Number.isNaN(s) ? 0 : s;
  }
  const o = t ? "Top" : "InlineStart", n = t ? "Bottom" : "InlineEnd";
  return {
    start: r(e[`border${o}Width`]) + r(e[`padding${o}`]),
    end: r(e[`border${n}Width`]) + r(e[`padding${n}`])
  };
}
function ze(e, t) {
  if (t.current != null && e.changedTouches) {
    const r = e;
    for (let o = 0; o < r.changedTouches.length; o += 1) {
      const n = r.changedTouches[o];
      if (n.identifier === t.current) return {
        x: n.clientX,
        y: n.clientY
      };
    }
    return null;
  }
  return {
    x: e.clientX,
    y: e.clientY
  };
}
var Nt = /* @__PURE__ */ a.forwardRef(function(t, r) {
  const { render: o, className: n, style: c, ...s } = t, { disabled: f, dragging: d, inset: m, lastChangedValueRef: v, lastChangeReasonRef: S, max: i, min: h, minStepsBetweenValues: R, onValueCommitted: w, orientation: N, pressedInputRef: D, pressedThumbCenterOffsetRef: H, pressedThumbIndexRef: B, pressedValuesRef: O, registerFieldControlRef: ae, renderBeforeHydration: X, setActive: Y, setDragging: $, setValue: Z, state: G, step: F, thumbCollisionBehavior: z, thumbRefs: x, values: y } = We(), J = st(), q = y.length > 1, ee = N === "vertical", E = a.useRef(null), k = a.useRef(null), Ne = K((l) => {
    l && k.current == null && k.current == null && (k.current = getComputedStyle(l));
  }), le = a.useRef(null), te = a.useRef(0), ce = a.useRef(0), ue = lt(y), Ce = K((l) => {
    B.current !== l && (B.current = l);
    const p = x.current[l];
    if (!p) {
      H.current = null, D.current = null;
      return;
    }
    D.current = p.querySelector('input[type="range"]');
  }), de = K((l) => {
    const p = E.current;
    if (!p) return null;
    const { width: b, height: C, bottom: A, left: _, right: ve } = p.getBoundingClientRect(), L = Er(k.current, ee), re = ce.current, ye = (ee ? C : b) - L.start - L.end - re * 2, Ae = H.current ?? 0, xe = l.x - Ae, Re = l.y - Ae, Te = ne(((ee ? A - Re - L.end : (J === "rtl" ? ve - xe : xe - _) - L.start) - re) / ye, 0, 1);
    let fe = (i - h) * Te + h;
    if (fe = St(fe, F, h), fe = ne(fe, h, i), !q) return {
      value: fe,
      thumbIndex: 0,
      didSwap: !1
    };
    const I = B.current;
    if (I < 0) return null;
    const me = Ar({
      behavior: z,
      values: y,
      currentValues: ue.current ?? y,
      initialValues: O.current,
      pressedIndex: I,
      nextValue: fe,
      min: h,
      max: i,
      step: F,
      minStepsBetweenValues: R
    });
    return z === "swap" && me.didSwap ? Ce(me.thumbIndex) : B.current = me.thumbIndex, me;
  }), W = K((l) => {
    O.current = q ? y.slice() : null, ue.current = y;
    const p = B.current;
    let b = p;
    if (p > -1 && p < y.length) {
      if (y[p] === i) {
        let C = p;
        for (; C > 0 && y[C - 1] === i; ) C -= 1;
        b = C;
      }
    } else {
      const C = ee ? "y" : "x";
      let A;
      b = -1;
      for (let _ = 0; _ < x.current.length; _ += 1) {
        const ve = x.current[_];
        if (Ye(ve)) {
          const L = It(ve), re = Math.abs(l[C] - L[C]);
          (A === void 0 || re <= A) && (b = _, A = re);
        }
      }
    }
    if (b > -1 && b !== p && Ce(b), m) {
      const C = x.current[b];
      Ye(C) && (ce.current = C.getBoundingClientRect()[ee ? "height" : "width"] / 2);
    }
  }), Q = K((l) => {
    const p = x.current?.[l]?.querySelector('input[type="range"]');
    p && p.focus({
      preventScroll: !0,
      focusVisible: !1
    });
  }), M = K((l) => {
    const p = ze(l, le);
    if (p == null) return;
    if (te.current += 1, l.type === "pointermove" && l.buttons === 0) {
      be(l);
      return;
    }
    const b = de(p);
    b != null && wt(b.value, F, R) && (!d && te.current > Tr && $(!0), Z(b.value, Me(Jt, l, void 0, { activeThumbIndex: b.thumbIndex })), ue.current = Array.isArray(b.value) ? b.value : [b.value], b.didSwap && Q(b.thumbIndex));
  });
  function be(l) {
    Y(-1), $(!1), D.current = null, H.current = null;
    const p = ze(l, le), b = p != null ? de(p) : null;
    if (b != null) {
      const C = S.current;
      w(v.current ?? b.value, at(C, l));
    }
    "pointerType" in l && E.current?.hasPointerCapture(l.pointerId) && E.current?.releasePointerCapture(l.pointerId), B.current = -1, le.current = null, O.current = null, j();
  }
  const U = K((l) => {
    if (f) return;
    const p = l.changedTouches[0];
    p != null && (le.current = p.identifier);
    const b = ze(l, le);
    if (b != null) {
      W(b);
      const A = de(b);
      if (A == null) return;
      Q(A.thumbIndex), Z(A.value, Me(et, l, void 0, { activeThumbIndex: A.thumbIndex })), ue.current = Array.isArray(A.value) ? A.value : [A.value], A.didSwap && Q(A.thumbIndex);
    }
    te.current = 0;
    const C = Ve(E.current);
    C.addEventListener("touchmove", M, { passive: !0 }), C.addEventListener("touchend", be, { passive: !0 });
  }), j = K(() => {
    const l = Ve(E.current);
    l.removeEventListener("pointermove", M), l.removeEventListener("pointerup", be), l.removeEventListener("touchmove", M), l.removeEventListener("touchend", be), O.current = null;
  }), ge = Wt();
  return a.useEffect(() => {
    const l = E.current;
    if (!l) return () => j();
    const p = Gt(l, "touchstart", U, { passive: !0 });
    return () => {
      p(), ge.cancel(), j();
    };
  }, [
    j,
    U,
    E,
    ge
  ]), a.useEffect(() => {
    f && j();
  }, [f, j]), Le("div", t, {
    state: G,
    ref: [
      r,
      ae,
      E,
      Ne
    ],
    props: [{
      "data-base-ui-slider-control": X ? "" : void 0,
      onPointerDown(l) {
        const p = E.current, b = Ut(l.nativeEvent);
        if (!p || f || l.defaultPrevented || !Ye(b) || l.button !== 0) return;
        const C = ze(l, le);
        if (C != null) {
          W(C);
          const _ = de(C);
          if (_ == null) return;
          ot(x.current[_.thumbIndex], it(Ve(p))) ? l.preventDefault() : ge.request(() => {
            Q(_.thumbIndex);
          }), $(!0), H.current == null && (Z(_.value, Me(et, l.nativeEvent, void 0, { activeThumbIndex: _.thumbIndex })), ue.current = Array.isArray(_.value) ? _.value : [_.value], _.didSwap && Q(_.thumbIndex));
        }
        l.nativeEvent.pointerId && p.setPointerCapture(l.nativeEvent.pointerId), te.current = 0;
        const A = Ve(E.current);
        A.addEventListener("pointermove", M, { passive: !0 }), A.addEventListener("pointerup", be, { once: !0 });
      }
    }, s],
    stateAttributesMapping: Be
  });
}), At = /* @__PURE__ */ a.forwardRef(function(t, r) {
  const { render: o, className: n, style: c, ...s } = t, { state: f } = We();
  return Le("div", t, {
    state: f,
    ref: r,
    props: [{ style: { position: "relative" } }, s],
    stateAttributesMapping: Be
  });
}), _r = /* @__PURE__ */ (function(e) {
  return e.index = "data-index", e.dragging = "data-dragging", e.orientation = "data-orientation", e.disabled = "data-disabled", e.valid = "data-valid", e.invalid = "data-invalid", e.touched = "data-touched", e.dirty = "data-dirty", e.focused = "data-focused", e;
})({});
var jr = /* @__PURE__ */ new Set([
  ht,
  mt,
  ft,
  ct,
  ut,
  "End",
  pt,
  dt
]);
function Vr(e, t, r, o) {
  if (!(t < 0))
    return e.length === 2 ? t === 0 ? `${qe(e[t], o, r)} start range` : `${qe(e[t], o, r)} end range` : r ? qe(e[t], o, r) : void 0;
}
function _e(e, t, r, o, n) {
  const c = r === 1 ? e + t : e - t;
  return ne(Number(c.toFixed(Math.max(ke(e), ke(t), ke(o)))), o, n);
}
var Tt = /* @__PURE__ */ a.forwardRef(function(t, r) {
  const { render: o, children: n, className: c, "aria-describedby": s, "aria-label": f, "aria-labelledby": d, disabled: m = !1, getAriaLabel: v, getAriaValueText: S, id: i, index: h, inputRef: R, onBlur: w, onFocus: N, onKeyDown: D, tabIndex: H, style: B, ...O } = t, { nonce: ae } = Xt(), X = Ge(i), { active: Y, lastUsedThumbIndex: $, controlRef: Z, disabled: G, validation: F, formatOptionsRef: z, handleInputChange: x, inset: y, labelId: J, largeStep: q, locale: ee, max: E, min: k, minStepsBetweenValues: Ne, form: le, name: te, orientation: ce, pressedInputRef: ue, pressedThumbCenterOffsetRef: Ce, pressedThumbIndexRef: de, renderBeforeHydration: W, setActive: Q, setIndicatorPosition: M, state: be, step: U, values: j } = We(), ge = st(), l = m || G, p = j.length > 1, b = ce === "vertical", C = ge === "rtl", { setTouched: A, setFocused: _, validationMode: ve } = bt(), L = a.useRef(null), re = a.useRef(null), ye = a.useRef(!1), Ae = Ge(), xe = fr(), Re = p ? Ae : xe, { ref: Te, index: fe } = tr({ metadata: a.useMemo(() => ({ inputId: Re }), [Re]) }), I = p ? h ?? fe : 0, me = I === j.length - 1, oe = j[I], we = Ze(oe, k, E), [Pe, Ie] = a.useState(), Se = gt(), je = $ >= 0 && $ < j.length ? $ : -1, he = K(() => {
    const g = Z.current, P = L.current;
    if (!g || !P) return;
    const V = P.getBoundingClientRect(), Ee = g.getBoundingClientRect(), $e = b ? "height" : "width", Lt = Ee[$e] - V[$e], Qe = (V[$e] / 2 + Lt * we / 100) / Ee[$e] * 100, Ke = Number.isFinite(Qe) ? Qe : void 0;
    Ie(Ke), I === 0 ? M((Xe) => [Ke, Xe[1]]) : me && M((Xe) => [Xe[0], Ke]);
  });
  He(() => {
    y && queueMicrotask(he);
  }, [he, y]), He(() => {
    y && he();
  }, [
    he,
    y,
    we
  ]), He(() => {
    if (!y || typeof ResizeObserver != "function") return;
    const g = Z.current, P = L.current;
    if (!g || !P) return;
    const V = new ResizeObserver(he);
    return V.observe(g), V.observe(P), () => {
      V.disconnect();
    };
  }, [
    Z,
    he,
    y
  ]);
  const Ue = a.useCallback(() => {
    const g = b ? "bottom" : "insetInlineStart", P = b ? "left" : "top";
    let V;
    return p ? Y === I ? V = 2 : je === I && (V = 1) : Y === I && (V = 1), y ? {
      "--position": `${Pe ?? 0}%`,
      visibility: W && Se || Pe === void 0 ? "hidden" : void 0,
      position: "absolute",
      [g]: "var(--position)",
      [P]: "50%",
      translate: `${(b || !C ? -1 : 1) * 50}% ${(b ? 1 : -1) * 50}%`,
      zIndex: V
    } : Number.isFinite(we) ? {
      position: "absolute",
      [g]: `${we}%`,
      [P]: "50%",
      translate: `${(b || !C ? -1 : 1) * 50}% ${(b ? 1 : -1) * 50}%`,
      zIndex: V
    } : tt;
  }, [
    Y,
    I,
    y,
    Se,
    Pe,
    p,
    W,
    C,
    je,
    we,
    b
  ]);
  let Oe;
  ce === "vertical" && (Oe = C ? "vertical-rl" : "vertical-lr");
  const T = typeof v == "function" ? v(I) : f, pe = Dt({
    "aria-label": T,
    "aria-labelledby": d ?? (T == null ? J : void 0),
    "aria-describedby": s,
    "aria-orientation": ce,
    "aria-valuenow": oe,
    "aria-valuetext": typeof S == "function" ? S(qe(oe, ee, z.current ?? void 0), oe, I) : Vr(j, I, z.current ?? void 0, ee),
    disabled: l,
    form: le,
    id: Re,
    max: E,
    min: k,
    name: te,
    onChange(g) {
      x(g.currentTarget.valueAsNumber, I, g);
    },
    onFocus(g) {
      const P = ye.current;
      ye.current = !1, Q(I), _(!0), P && g.stopPropagation();
    },
    onBlur(g) {
      if (ye.current) {
        g.stopPropagation();
        return;
      }
      L.current && (Q(-1), A(!0), _(!1), ve === "onBlur" && F.commit(Rt(oe, I, k, E, p, j)));
    },
    onKeyDown(g) {
      if (!jr.has(g.key)) return;
      nr.has(g.key) && g.stopPropagation();
      let P = null;
      const V = St(oe, U, k);
      switch (g.key) {
        case ht:
          P = _e(V, g.shiftKey ? q : U, 1, k, E);
          break;
        case ct:
          P = _e(V, g.shiftKey ? q : U, C ? -1 : 1, k, E);
          break;
        case mt:
          P = _e(V, g.shiftKey ? q : U, -1, k, E);
          break;
        case ft:
          P = _e(V, g.shiftKey ? q : U, C ? 1 : -1, k, E);
          break;
        case pt:
          P = _e(V, q, 1, k, E);
          break;
        case dt:
          P = _e(V, q, -1, k, E);
          break;
        case "End":
          P = E, p && (P = Number.isFinite(j[I + 1]) ? j[I + 1] - U * Ne : E);
          break;
        case ut:
          P = k, p && (P = Number.isFinite(j[I - 1]) ? j[I - 1] + U * Ne : k);
          break;
        default:
          break;
      }
      if (P !== null) {
        const Ee = g.currentTarget;
        Kt(Ee) || (ye.current = !0, Ee.blur(), Ee.focus({
          preventScroll: !0,
          focusVisible: !0
        })), x(P, I, g), g.preventDefault();
      }
    },
    step: U,
    style: {
      ...tt,
      width: "100%",
      height: "100%",
      writingMode: Oe
    },
    tabIndex: H ?? void 0,
    type: "range",
    value: oe ?? ""
  }, F.getInputValidationProps), ie = Ht(re, F.inputRef, R);
  return Le("div", t, {
    state: be,
    ref: [
      r,
      Te,
      L
    ],
    props: [{
      [_r.index]: I,
      children: /* @__PURE__ */ (0, u.jsxs)(a.Fragment, { children: [
        n,
        /* @__PURE__ */ (0, u.jsx)("input", {
          ref: ie,
          ...pe,
          suppressHydrationWarning: !0
        }),
        y && Se && W && me && /* @__PURE__ */ (0, u.jsx)("script", {
          nonce: ae,
          dangerouslySetInnerHTML: { __html: '!function(){const t=document.currentScript?.parentElement;if(!t)return;const e=t.closest("[data-base-ui-slider-control]");if(!e)return;const r=e.querySelector("[data-base-ui-slider-indicator]"),i=e.getBoundingClientRect(),n="vertical"===e.getAttribute("data-orientation")?"height":"width",o=e.querySelectorAll(\'input[type="range"]\'),l=o.length>1,s=o.length-1;let a=null,u=null;for(let t=0;t<o.length;t+=1){const e=o[t],y=parseFloat(e.getAttribute("value")??"");if(Number.isNaN(y))return;const c=e.parentElement;if(!c)return;const p=parseFloat(e.getAttribute("max")??"100"),g=parseFloat(e.getAttribute("min")??"0"),b=c?.getBoundingClientRect(),d=i[n]-b[n],m=100*(y-g)/(p-g),v=(b[n]/2+d*m/100)/i[n]*100;c.style.setProperty("--position",`${v}%`),Number.isFinite(v)&&(c.style.removeProperty("visibility"),r&&(0===t?(a=v,r.style.setProperty("--start-position",`${v}%`),l||r.style.removeProperty("visibility")):t===s&&(u=v-(a??0),r.style.setProperty("--end-position",`${v}%`),r.style.setProperty("--relative-size",`${u}%`),r.style.removeProperty("visibility"))))}}();' },
          suppressHydrationWarning: !0
        })
      ] }),
      id: X,
      onBlur: w,
      onFocus: N,
      onPointerDown(g) {
        if (de.current = I, L.current != null) {
          const P = ce === "horizontal" ? "x" : "y", V = It(L.current);
          Ce.current = (ce === "horizontal" ? g.clientX : g.clientY) - V[P];
        }
        re.current != null && ue.current !== re.current && (ue.current = re.current);
      },
      style: Ue(),
      suppressHydrationWarning: W || void 0
    }, O],
    stateAttributesMapping: Be
  });
});
function Fr(e, t, r, o, n, c) {
  const s = r === void 0 || t && o === void 0 ? "hidden" : void 0, f = e ? "bottom" : "insetInlineStart", d = e ? "height" : "width", m = {
    visibility: n && c ? "hidden" : s,
    position: e ? "absolute" : "relative",
    [e ? "width" : "height"]: "inherit"
  };
  return m["--start-position"] = `${r ?? 0}%`, t ? (m["--relative-size"] = `${(o ?? 0) - (r ?? 0)}%`, m[f] = "var(--start-position)", m[d] = "var(--relative-size)", m) : (m[f] = 0, m[d] = "var(--start-position)", m);
}
function Mr(e, t, r, o) {
  const n = e ? "bottom" : "insetInlineStart", c = e ? "height" : "width", s = {
    position: e ? "absolute" : "relative",
    [e ? "width" : "height"]: "inherit"
  };
  if (!t)
    return s[n] = 0, s[c] = `${r}%`, s;
  const f = o - r;
  return s[n] = `${r}%`, s[c] = `${f}%`, s;
}
var Et = /* @__PURE__ */ a.forwardRef(function(t, r) {
  const { render: o, className: n, style: c, ...s } = t, { indicatorPosition: f, inset: d, max: m, min: v, orientation: S, renderBeforeHydration: i, state: h, values: R } = We(), w = gt(), N = S === "vertical", D = R.length > 1, H = d ? Fr(N, D, f[0], f[1], i, w) : Mr(N, D, Ze(R[0], v, m), Ze(R[R.length - 1], v, m));
  return Le("div", t, {
    state: h,
    ref: r,
    props: [{
      "data-base-ui-slider-indicator": i ? "" : void 0,
      style: H,
      suppressHydrationWarning: i || void 0
    }, s],
    stateAttributesMapping: Be
  });
});
function _t(e) {
  const t = (0, a.useRef)(null), [r, o] = (0, a.useState)("ltr");
  return (0, a.useEffect)(() => {
    if (e) return;
    const n = () => {
      if (t.current) {
        const s = getComputedStyle(t.current).direction;
        o(s === "rtl" ? "rtl" : "ltr");
      }
    };
    n();
    const c = new MutationObserver(n);
    if (t.current) {
      const s = t.current.closest("[dir]"), f = t.current.ownerDocument.documentElement;
      s && c.observe(s, {
        attributes: !0,
        attributeFilter: ["dir"]
      }), f !== s && c.observe(f, {
        attributes: !0,
        attributeFilter: ["dir"]
      });
    }
    return () => c.disconnect();
  }, [e]), {
    ref: t,
    direction: e ?? r
  };
}
var jt = {
  sm: "data-[orientation=horizontal]:h-1.5 data-[orientation=vertical]:w-1.5",
  md: "data-[orientation=horizontal]:h-2 data-[orientation=vertical]:w-2",
  lg: "data-[orientation=horizontal]:h-3 data-[orientation=vertical]:w-3"
}, Vt = {
  primary: {
    indicator: "bg-primary",
    track: "bg-muted",
    thumb: "border-primary ring-primary/20"
  },
  info: {
    indicator: "bg-info",
    track: "bg-info/20",
    thumb: "border-info ring-info/20"
  },
  success: {
    indicator: "bg-success",
    track: "bg-success/20",
    thumb: "border-success ring-success/20"
  },
  warning: {
    indicator: "bg-warning",
    track: "bg-warning/20",
    thumb: "border-warning ring-warning/20"
  },
  error: {
    indicator: "bg-destructive",
    track: "bg-destructive/20",
    thumb: "border-destructive ring-destructive/20"
  }
}, kr = (0, a.forwardRef)(({ className: e, defaultValue: t, value: r, min: o = 0, max: n = 100, dir: c, size: s = "md", color: f = "primary", ...d }, m) => {
  const { ref: v, direction: S } = _t(c), i = Vt[f], h = (0, a.useMemo)(() => Array.isArray(r) ? r : Array.isArray(t) ? t : [o], [
    r,
    t,
    o
  ]);
  return /* @__PURE__ */ (0, u.jsx)("div", {
    ref: v,
    className: "contents",
    children: /* @__PURE__ */ (0, u.jsx)(vt, {
      direction: S,
      children: /* @__PURE__ */ (0, u.jsx)(Pt, {
        ref: m,
        className: "data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full",
        "data-slot": "slider",
        "data-color": f,
        "data-size": s,
        defaultValue: t,
        value: r,
        min: o,
        max: n,
        ...d,
        children: /* @__PURE__ */ (0, u.jsxs)(Nt, {
          className: se("group/slider data-[orientation=vertical]:min-h-40 relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col", e),
          children: [/* @__PURE__ */ (0, u.jsx)(At, {
            "data-slot": "slider-track",
            className: se("rounded-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full relative overflow-hidden select-none transition-transform duration-200 ease-out origin-center data-[orientation=horizontal]:group-hover/slider:scale-y-[1.5] data-[orientation=vertical]:group-hover/slider:scale-x-[1.5] motion-reduce:transition-none motion-reduce:group-hover/slider:scale-100", jt[s], i.track),
            children: /* @__PURE__ */ (0, u.jsx)(Et, {
              "data-slot": "slider-range",
              className: se("select-none data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full", i.indicator)
            })
          }), Array.from({ length: h.length }, (R, w) => /* @__PURE__ */ (0, u.jsx)(Tt, {
            "data-slot": "slider-thumb",
            className: se("relative size-5 rounded-full border-2 bg-background shadow-sm transition-[color,box-shadow,transform] duration-150 ease-out hover:ring-4 hover:scale-110 focus-visible:ring-4 focus-visible:scale-110 active:scale-105 data-[dragging]:shadow-md data-[dragging]:scale-110 focus-visible:outline-hidden block shrink-0 select-none disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none motion-reduce:hover:scale-100 motion-reduce:focus-visible:scale-100 motion-reduce:active:scale-100 motion-reduce:data-[dragging]:scale-100 before:absolute before:-inset-3 before:rounded-full", i.thumb)
          }, w))]
        })
      })
    })
  });
});
kr.displayName = "Slider";
var De = (e) => {
  if (e !== void 0)
    return typeof e == "number" ? [e] : [...e];
}, Lr = ({ id: e, value: t, format: r }) => /* @__PURE__ */ (0, u.jsxs)("div", {
  id: e,
  role: "tooltip",
  className: "absolute left-1/2 -translate-x-1/2 bottom-full mb-2 flex flex-col items-center",
  children: [/* @__PURE__ */ (0, u.jsx)("div", {
    className: "bg-foreground px-3 py-1.5 rounded-md",
    children: /* @__PURE__ */ (0, u.jsx)("span", {
      className: "text-xs font-normal text-background whitespace-nowrap",
      children: r ? r(t) : `${t}%`
    })
  }), /* @__PURE__ */ (0, u.jsx)("svg", {
    width: "8",
    height: "4",
    viewBox: "0 0 8 4",
    fill: "none",
    className: "text-foreground",
    "aria-hidden": "true",
    children: /* @__PURE__ */ (0, u.jsx)("path", {
      d: "M4 4L0 0H8L4 4Z",
      fill: "currentColor"
    })
  })]
}), Ft = (0, a.forwardRef)(({ className: e, defaultValue: t, value: r, min: o = 0, max: n = 100, size: c = "md", color: s = "primary", thumbCount: f, onValueChange: d, ...m }, v) => {
  const S = f ?? (Array.isArray(r) ? r.length : Array.isArray(t) ? t.length : 1), i = Vt[s];
  return /* @__PURE__ */ (0, u.jsx)(Pt, {
    ref: v,
    className: "data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full",
    "data-slot": "slider",
    "data-color": s,
    "data-size": c,
    defaultValue: t,
    value: r,
    min: o,
    max: n,
    onValueChange: d,
    ...m,
    children: /* @__PURE__ */ (0, u.jsxs)(Nt, {
      className: se("group/slider data-[orientation=vertical]:min-h-40 relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col", e),
      children: [/* @__PURE__ */ (0, u.jsx)(At, {
        "data-slot": "slider-track",
        className: se("rounded-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full relative overflow-hidden select-none transition-transform duration-200 ease-out origin-center data-[orientation=horizontal]:group-hover/slider:scale-y-[1.5] data-[orientation=vertical]:group-hover/slider:scale-x-[1.5] motion-reduce:transition-none motion-reduce:group-hover/slider:scale-100", jt[c], i.track),
        children: /* @__PURE__ */ (0, u.jsx)(Et, {
          "data-slot": "slider-range",
          className: se("select-none data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full", i.indicator)
        })
      }), Array.from({ length: S }, (h, R) => /* @__PURE__ */ (0, u.jsx)(Tt, {
        "data-slot": "slider-thumb",
        className: se("relative size-5 rounded-full border-2 bg-background shadow-sm transition-[color,box-shadow,transform] duration-150 ease-out hover:ring-4 hover:scale-110 focus-visible:ring-4 focus-visible:scale-110 active:scale-105 data-[dragging]:shadow-md data-[dragging]:scale-110 focus-visible:outline-hidden block shrink-0 select-none disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none motion-reduce:hover:scale-100 motion-reduce:focus-visible:scale-100 motion-reduce:active:scale-100 motion-reduce:data-[dragging]:scale-100 before:absolute before:-inset-3 before:rounded-full", i.thumb)
      }, R))]
    })
  });
});
Ft.displayName = "SliderBase";
var Je = (0, a.forwardRef)(({ mode: e = "single", size: t = "md", color: r = "primary", label: o, labelMode: n = "none", valueFormat: c, showMinMax: s, hint: f, min: d = 0, max: m = 100, value: v, defaultValue: S, className: i, onValueChange: h, dir: R, ...w }, N) => {
  const { ref: D, direction: H } = _t(R), B = (0, a.useId)(), O = (0, a.useMemo)(() => {
    if (v !== void 0) return;
    const x = De(S);
    return x !== void 0 ? x : e === "range" ? [d, m] : [d];
  }, [
    S,
    e,
    d,
    m,
    v
  ]), [ae, X] = (0, a.useState)(De(v) ?? O ?? (e === "range" ? [d, m] : [d])), Y = De(v) ?? ae, $ = (x) => {
    const y = De(x) ?? [];
    v === void 0 && X(y), h?.(y);
  }, Z = (x) => c ? c(x) : `${x}%`, G = (x) => (x - d) / (m - d) * 100, F = H === "rtl" ? "translateX(50%)" : "translateX(-50%)", z = n === "bottom" ? "h-14" : n === "floating" ? "h-12" : "h-6";
  return /* @__PURE__ */ (0, u.jsx)("div", {
    ref: D,
    className: se("w-full space-y-3", i),
    children: /* @__PURE__ */ (0, u.jsxs)(vt, {
      direction: H,
      children: [
        o && /* @__PURE__ */ (0, u.jsx)(or, {
          className: "text-sm font-medium",
          children: o
        }),
        /* @__PURE__ */ (0, u.jsxs)("div", {
          className: se("relative w-full", z),
          children: [
            n === "floating" && Y.map((x, y) => /* @__PURE__ */ (0, u.jsx)("div", {
              className: "absolute top-0 transition-[inset-inline-start] duration-100 ease-out motion-reduce:transition-none",
              style: {
                insetInlineStart: `${G(x)}%`,
                transform: F
              },
              children: /* @__PURE__ */ (0, u.jsx)(Lr, {
                id: `${B}-tooltip-${y}`,
                value: x,
                format: c
              })
            }, y)),
            /* @__PURE__ */ (0, u.jsx)("div", {
              className: se("absolute inset-x-0", n === "floating" ? "top-8" : "top-2"),
              children: /* @__PURE__ */ (0, u.jsx)(Ft, {
                ref: N,
                min: d,
                max: m,
                size: t,
                color: r,
                thumbCount: Y.length,
                value: Y,
                defaultValue: O,
                onValueChange: $,
                ...w
              })
            }),
            n === "bottom" && Y.map((x, y) => /* @__PURE__ */ (0, u.jsx)("div", {
              className: "absolute bottom-0 transition-[inset-inline-start] duration-100 ease-out motion-reduce:transition-none",
              style: {
                insetInlineStart: `${G(x)}%`,
                transform: F
              },
              children: /* @__PURE__ */ (0, u.jsx)("span", {
                className: "text-base font-medium text-foreground whitespace-nowrap",
                children: Z(x)
              })
            }, y))
          ]
        }),
        s && /* @__PURE__ */ (0, u.jsxs)("div", {
          className: "flex justify-between text-xs text-muted-foreground",
          children: [/* @__PURE__ */ (0, u.jsx)("span", { children: d }), /* @__PURE__ */ (0, u.jsx)("span", { children: m })]
        }),
        f && /* @__PURE__ */ (0, u.jsx)("p", {
          className: "text-sm text-muted-foreground",
          children: f
        })
      ]
    })
  });
});
Je.displayName = "SliderControl";
var Mt = (0, a.forwardRef)((e, t) => {
  const [r, o] = sr(e);
  if (!ar(r)) return /* @__PURE__ */ (0, u.jsx)(Je, {
    ref: t,
    ...o,
    label: r.label
  });
  const { label: n, required: c, labelIcon: s, tooltip: f, topRight: d, description: m, bottomRight: v, error: S, fieldClassName: i } = r, h = o, R = n || d, w = m || v || S;
  return /* @__PURE__ */ (0, u.jsxs)(Rr, {
    state: S ? "destructive" : void 0,
    disabled: h.disabled,
    className: i,
    children: [
      R && /* @__PURE__ */ (0, u.jsxs)(hr, { children: [n && /* @__PURE__ */ (0, u.jsxs)(xr, {
        required: c,
        labelIcon: s,
        children: [n, f && /* @__PURE__ */ (0, u.jsx)(ir, { content: f })]
      }), d && /* @__PURE__ */ (0, u.jsx)(br, { children: d })] }),
      /* @__PURE__ */ (0, u.jsx)(pr, { children: () => /* @__PURE__ */ (0, u.jsx)(Je, {
        ref: t,
        ...h
      }) }),
      w && /* @__PURE__ */ (0, u.jsxs)(gr, { children: [
        S && /* @__PURE__ */ (0, u.jsx)(vr, { children: S }),
        !S && m && /* @__PURE__ */ (0, u.jsx)(mr, { children: m }),
        v && /* @__PURE__ */ (0, u.jsx)(yr, {
          className: "ms-auto",
          children: v
        })
      ] })
    ]
  });
});
Mt.displayName = "Slider";
var Br = $t(), Fe = {};
function nt(e, t) {
  if (e !== null)
    switch (t) {
      case "number":
        return Number(e);
      case "boolean":
        return e !== "false" && e !== "0";
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
}
var kt = class extends HTMLElement {
  _root = null;
  _childrenContainer = null;
  _props = {};
  _initialized = !1;
  connectedCallback() {
    setTimeout(() => this._initialize(), 0);
  }
  _initialize() {
    if (this._initialized) return;
    this._initialized = !0;
    const e = [];
    for (const r of Array.from(this.childNodes))
      r.nodeType === Node.TEXT_NODE && !r.textContent?.trim() || e.push(r);
    const t = document.createElement("div");
    for (t.style.display = "contents", this._childrenContainer = document.createElement("div"), this._childrenContainer.style.display = "contents", e.forEach((r) => this._childrenContainer.appendChild(r)); this.firstChild; ) this.removeChild(this.firstChild);
    this.appendChild(t), this._root = (0, Br.createRoot)(t), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(e, t, r) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(Fe).map((e) => e.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(e, t) {
    const r = Fe[e] || "string";
    this._props[e] = this._parseValue(t, r), this._render();
  }
  _parseValue(e, t) {
    if (t === "boolean" && typeof e == "boolean" || t === "number" && typeof e == "number" || t === "string" && typeof e == "string") return e;
    if (typeof e == "string") switch (t) {
      case "boolean":
        return e !== "false" && e !== "0" && e !== "";
      case "number":
        return Number(e);
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
    return e;
  }
  _getProp(e) {
    if (e in this._props) return this._props[e];
    const t = e.replace(/([A-Z])/g, "-$1").toLowerCase(), r = Fe[e] || "string";
    return nt(this.getAttribute(t), r);
  }
  _render() {
    if (!this._root) return;
    const e = {};
    for (const [r, o] of Object.entries(Fe)) if (r in this._props) e[r] = this._props[r];
    else {
      const n = r.replace(/([A-Z])/g, "-$1").toLowerCase();
      e[r] = nt(this.getAttribute(n), o);
    }
    const t = a.createElement(Mt, {
      ...e,
      _hostElement: this
    });
    this._root.render(t);
  }
};
for (const e of Object.keys(Fe)) Object.defineProperty(kt.prototype, e, {
  get() {
    return this._getProp(e);
  },
  set(t) {
    this._setProp(e, t);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-slider") && customElements.define("hf-slider", kt);
export {
  kt as SliderWC,
  kt as default
};

//# sourceMappingURL=hf-slider.js.map