import Y from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import _ from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as n from "react";
function G(s) {
  var p = "touches" in s ? s.touches[0] : s;
  return {
    pageX: p.pageX,
    pageY: p.pageY
  };
}
function ae(s, p, o, L, M, H, J, K, N) {
  var Q = n.useState(null), C = _(Q, 2), W = C[0], D = C[1], Z = n.useState(-1), P = _(Z, 2), $ = P[0], k = P[1], I = n.useState(o), y = _(I, 2), m = y[0], U = y[1], w = n.useState(o), V = _(w, 2), d = V[0], x = V[1], h = n.useRef(null), l = n.useRef(null);
  n.useEffect(function() {
    $ === -1 && U(o);
  }, [o, $]), n.useEffect(function() {
    return function() {
      document.removeEventListener("mousemove", h.current), document.removeEventListener("mouseup", l.current), document.removeEventListener("touchmove", h.current), document.removeEventListener("touchend", l.current);
    };
  }, []);
  var A = function(t, e) {
    m.some(function(r, v) {
      return r !== t[v];
    }) && (e !== void 0 && D(e), U(t), J(t));
  }, j = function(t, e) {
    if (t === -1) {
      var r = d[0], v = d[d.length - 1], b = L - r, E = M - v, u = e * (M - L);
      u = Math.max(u, b), u = Math.min(u, E);
      var X = H(r + u);
      u = X - r;
      var a = d.map(function(S) {
        return S + u;
      });
      A(a);
    } else {
      var g = (M - L) * e, i = Y(m);
      i[t] = d[t];
      var c = N(i, g, t, "dist");
      A(c.values, c.value);
    }
  }, B = n.useRef(j);
  B.current = j;
  var ee = function(t, e, r) {
    t.stopPropagation();
    var v = r || o, b = v[e];
    k(e), D(b), x(v);
    var E = G(t), u = E.pageX, X = E.pageY, a = function(c) {
      c.preventDefault();
      var S = G(c), re = S.pageX, ne = S.pageY, O = re - u, T = ne - X, q = s.current.getBoundingClientRect(), z = q.width, F = q.height, f;
      switch (p) {
        case "btt":
          f = -T / F;
          break;
        case "ttb":
          f = T / F;
          break;
        case "rtl":
          f = -O / z;
          break;
        default:
          f = O / z;
      }
      B.current(e, f);
    }, g = function i(c) {
      c.preventDefault(), document.removeEventListener("mouseup", i), document.removeEventListener("mousemove", a), document.removeEventListener("touchend", i), document.removeEventListener("touchmove", a), h.current = null, l.current = null, k(-1), K();
    };
    document.addEventListener("mouseup", g), document.addEventListener("mousemove", a), document.addEventListener("touchend", g), document.addEventListener("touchmove", a), h.current = a, l.current = g;
  }, te = n.useMemo(function() {
    var R = Y(o).sort(function(e, r) {
      return e - r;
    }), t = Y(m).sort(function(e, r) {
      return e - r;
    });
    return R.every(function(e, r) {
      return e === t[r];
    }) ? m : o;
  }, [o, m]);
  return [$, W, te, ee];
}
export {
  ae as default
};
