import $e from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import P from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import I from "../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import M from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import ua from "../../@babel/runtime/helpers/esm/typeof.mjs";
import we from "../../classnames/index.mjs";
import sa from "../../rc-util/es/hooks/useMergedState.mjs";
import ca from "../../rc-util/es/isEqual.mjs";
import { warningOnce as He } from "../../rc-util/es/warning.mjs";
import * as t from "react";
import da from "./context.mjs";
import fa from "./Handles/index.mjs";
import ma from "./hooks/useDrag.mjs";
import va from "./hooks/useOffset.mjs";
import ga from "./Marks/index.mjs";
import ha from "./Steps/index.mjs";
import ba from "./Tracks/index.mjs";
var ya = /* @__PURE__ */ t.forwardRef(function(e, Oe) {
  var y, Q = e.prefixCls, u = Q === void 0 ? "rc-slider" : Q, Te = e.className, De = e.style, k = e.classNames, E = e.styles, U = e.disabled, x = U === void 0 ? !1 : U, W = e.keyboard, Z = W === void 0 ? !0 : W, Ne = e.autoFocus, Le = e.onFocus, Be = e.onBlur, ee = e.min, j = ee === void 0 ? 0 : ee, ae = e.max, X = ae === void 0 ? 100 : ae, re = e.step, H = re === void 0 ? 1 : re, Ae = e.value, Pe = e.defaultValue, f = e.range, F = e.count, te = e.onChange, d = e.onBeforeChange, O = e.onAfterChange, Y = e.onChangeComplete, ne = e.allowCross, Ie = ne === void 0 ? !0 : ne, le = e.pushable, R = le === void 0 ? !1 : le, p = e.draggableTrack, q = e.reverse, T = e.vertical, oe = e.included, ie = oe === void 0 ? !0 : oe, je = e.startPoint, Xe = e.trackStyle, Ye = e.handleStyle, pe = e.railStyle, qe = e.dotStyle, ze = e.activeDotStyle, z = e.marks, Ke = e.dots, Ge = e.handleRender, ue = e.tabIndex, se = ue === void 0 ? 0 : ue, ce = e.ariaLabelForHandle, de = e.ariaLabelledByForHandle, fe = e.ariaValueTextFormatterForHandle, V = t.useRef(), D = t.useRef(), N = t.useMemo(function() {
    return T ? q ? "ttb" : "btt" : q ? "rtl" : "ltr";
  }, [q, T]), i = t.useMemo(function() {
    return isFinite(j) ? j : 0;
  }, [j]), C = t.useMemo(function() {
    return isFinite(X) ? X : 100;
  }, [X]), g = t.useMemo(function() {
    return H !== null && H <= 0 ? 1 : H;
  }, [H]), Je = t.useMemo(function() {
    return typeof R == "boolean" ? R ? g : !1 : R >= 0 ? R : !1;
  }, [R, g]), L = t.useMemo(function() {
    var n = Object.keys(z || {});
    return n.map(function(r) {
      var a = z[r], o = {
        value: Number(r)
      };
      return a && ua(a) === "object" && !/* @__PURE__ */ t.isValidElement(a) && ("label" in a || "style" in a) ? (o.style = a.style, o.label = a.label) : o.label = a, o;
    }).filter(function(r) {
      var a = r.label;
      return a || typeof a == "number";
    }).sort(function(r, a) {
      return r.value - a.value;
    });
  }, [z]), Qe = va(i, C, g, L, Ie, Je), me = M(Qe, 2), B = me[0], ve = me[1], Ue = sa(Pe, {
    value: Ae
  }), ge = M(Ue, 2), m = ge[0], We = ge[1], s = t.useMemo(function() {
    var n = m == null ? [] : Array.isArray(m) ? m : [m], r = M(n, 1), a = r[0], o = a === void 0 ? i : a, l = m === null ? [] : [o];
    if (f) {
      if (l = I(n), F || m === void 0) {
        var c = F >= 0 ? F + 1 : 2;
        for (l = l.slice(0, c); l.length < c; ) {
          var h;
          l.push((h = l[l.length - 1]) !== null && h !== void 0 ? h : i);
        }
      }
      l.sort(function(b, v) {
        return b - v;
      });
    }
    return l.forEach(function(b, v) {
      l[v] = B(b);
    }), l;
  }, [m, f, i, F, B]), $ = t.useRef(s);
  $.current = s;
  var S = function(r) {
    return f ? r : r[0];
  }, K = function(r) {
    var a = I(r).sort(function(o, l) {
      return o - l;
    });
    te && !ca(a, $.current, !0) && te(S(a)), We(a);
  }, he = function() {
    O == null || O(S($.current)), He(!O, "[rc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead."), Y == null || Y(S($.current));
  }, Ze = ma(D, N, s, i, C, B, K, he, ve), A = M(Ze, 4), be = A[0], ea = A[1], G = A[2], ye = A[3], Ce = function(r, a) {
    if (!x) {
      var o = 0, l = C - i;
      s.forEach(function(h, b) {
        var v = Math.abs(r - h);
        v <= l && (l = v, o = b);
      });
      var c = I(s);
      c[o] = r, f && !s.length && F === void 0 && c.push(r), d == null || d(S(c)), K(c), a && ye(a, o, c);
    }
  }, aa = function(r) {
    r.preventDefault();
    var a = D.current.getBoundingClientRect(), o = a.width, l = a.height, c = a.left, h = a.top, b = a.bottom, v = a.right, Re = r.clientX, Ve = r.clientY, w;
    switch (N) {
      case "btt":
        w = (b - Ve) / l;
        break;
      case "ttb":
        w = (Ve - h) / l;
        break;
      case "rtl":
        w = (v - Re) / o;
        break;
      default:
        w = (Re - c) / o;
    }
    var ia = i + w * (C - i);
    Ce(B(ia), r);
  }, ra = t.useState(null), Se = M(ra, 2), J = Se[0], _e = Se[1], ta = function(r, a) {
    if (!x) {
      var o = ve(s, r, a);
      d == null || d(S(s)), K(o.values), _e(o.value);
    }
  };
  t.useEffect(function() {
    if (J !== null) {
      var n = s.indexOf(J);
      n >= 0 && V.current.focus(n);
    }
    _e(null);
  }, [J]);
  var na = t.useMemo(function() {
    return p && g === null ? (process.env.NODE_ENV !== "production" && He(!1, "`draggableTrack` is not supported when `step` is `null`."), !1) : p;
  }, [p, g]), Me = function(r, a) {
    ye(r, a), d == null || d(S($.current));
  }, ke = be !== -1;
  t.useEffect(function() {
    if (!ke) {
      var n = s.lastIndexOf(ea);
      V.current.focus(n);
    }
  }, [ke]);
  var _ = t.useMemo(function() {
    return I(G).sort(function(n, r) {
      return n - r;
    });
  }, [G]), la = t.useMemo(function() {
    return f ? [_[0], _[_.length - 1]] : [i, _[0]];
  }, [_, f, i]), Ee = M(la, 2), xe = Ee[0], Fe = Ee[1];
  t.useImperativeHandle(Oe, function() {
    return {
      focus: function() {
        V.current.focus(0);
      },
      blur: function() {
        var r = document, a = r.activeElement;
        D.current.contains(a) && (a == null || a.blur());
      }
    };
  }), t.useEffect(function() {
    Ne && V.current.focus(0);
  }, []);
  var oa = t.useMemo(function() {
    return {
      min: i,
      max: C,
      direction: N,
      disabled: x,
      keyboard: Z,
      step: g,
      included: ie,
      includedStart: xe,
      includedEnd: Fe,
      range: f,
      tabIndex: se,
      ariaLabelForHandle: ce,
      ariaLabelledByForHandle: de,
      ariaValueTextFormatterForHandle: fe,
      styles: E || {},
      classNames: k || {}
    };
  }, [i, C, N, x, Z, g, ie, xe, Fe, f, se, ce, de, fe, E, k]);
  return /* @__PURE__ */ t.createElement(da.Provider, {
    value: oa
  }, /* @__PURE__ */ t.createElement("div", {
    ref: D,
    className: we(u, Te, (y = {}, P(y, "".concat(u, "-disabled"), x), P(y, "".concat(u, "-vertical"), T), P(y, "".concat(u, "-horizontal"), !T), P(y, "".concat(u, "-with-marks"), L.length), y)),
    style: De,
    onMouseDown: aa
  }, /* @__PURE__ */ t.createElement("div", {
    className: we("".concat(u, "-rail"), k == null ? void 0 : k.rail),
    style: $e($e({}, pe), E == null ? void 0 : E.rail)
  }), /* @__PURE__ */ t.createElement(ba, {
    prefixCls: u,
    style: Xe,
    values: _,
    startPoint: je,
    onStartMove: na ? Me : null
  }), /* @__PURE__ */ t.createElement(ha, {
    prefixCls: u,
    marks: L,
    dots: Ke,
    style: qe,
    activeStyle: ze
  }), /* @__PURE__ */ t.createElement(fa, {
    ref: V,
    prefixCls: u,
    style: Ye,
    values: G,
    draggingIndex: be,
    onStartMove: Me,
    onOffsetChange: ta,
    onFocus: Le,
    onBlur: Be,
    handleRender: Ge,
    onChangeComplete: he
  }), /* @__PURE__ */ t.createElement(ga, {
    prefixCls: u,
    marks: L,
    onClick: Ce
  })));
});
process.env.NODE_ENV !== "production" && (ya.displayName = "Slider");
export {
  ya as default
};
