import J from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as k from "react";
function Q(v, g, M, S, G, b) {
  var F = k.useCallback(function(o) {
    var n = isFinite(o) ? o : v;
    return n = Math.min(g, o), n = Math.max(v, n), n;
  }, [v, g]), y = k.useCallback(function(o) {
    if (M !== null) {
      var n = v + Math.round((F(o) - v) / M) * M, u = function(f) {
        return (String(f).split(".")[1] || "").length;
      }, t = Math.max(u(M), u(g), u(v)), a = Number(n.toFixed(t));
      return v <= a && a <= g ? a : null;
    }
    return null;
  }, [M, v, g, F]), A = k.useCallback(function(o) {
    var n = F(o), u = S.map(function(r) {
      return r.value;
    });
    M !== null && u.push(y(o)), u.push(v, g);
    var t = u[0], a = g - v;
    return u.forEach(function(r) {
      var f = Math.abs(n - r);
      f <= a && (t = r, a = f);
    }), t;
  }, [v, g, S, M, F, y]), O = function o(n, u, t) {
    var a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "unit";
    if (typeof u == "number") {
      var r, f = n[t], R = f + u, h = [];
      S.forEach(function(c) {
        h.push(c.value);
      }), h.push(v, g), h.push(y(f));
      var e = u > 0 ? 1 : -1;
      a === "unit" ? h.push(y(f + e * M)) : h.push(y(R)), h = h.filter(function(c) {
        return c !== null;
      }).filter(function(c) {
        return u < 0 ? c <= f : c >= f;
      }), a === "unit" && (h = h.filter(function(c) {
        return c !== f;
      }));
      var i = a === "unit" ? f : R;
      r = h[0];
      var E = Math.abs(r - i);
      if (h.forEach(function(c) {
        var C = Math.abs(c - i);
        C < E && (r = c, E = C);
      }), r === void 0)
        return u < 0 ? v : g;
      if (a === "dist")
        return r;
      if (Math.abs(u) > 1) {
        var s = J(n);
        return s[t] = r, o(s, u - e, t, a);
      }
      return r;
    } else {
      if (u === "min")
        return v;
      if (u === "max")
        return g;
    }
  }, N = function(n, u, t) {
    var a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "unit", r = n[t], f = O(n, u, t, a);
    return {
      value: f,
      changed: f !== r
    };
  }, P = function(n) {
    return b === null && n === 0 || typeof b == "number" && n < b;
  }, H = function(n, u, t) {
    var a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "unit", r = n.map(A), f = r[t], R = O(r, u, t, a);
    if (r[t] = R, G === !1) {
      var h = b || 0;
      t > 0 && r[t - 1] !== f && (r[t] = Math.max(r[t], r[t - 1] + h)), t < r.length - 1 && r[t + 1] !== f && (r[t] = Math.min(r[t], r[t + 1] - h));
    } else if (typeof b == "number" || b === null) {
      for (var e = t + 1; e < r.length; e += 1)
        for (var i = !0; P(r[e] - r[e - 1]) && i; ) {
          var E = N(r, 1, e);
          r[e] = E.value, i = E.changed;
        }
      for (var s = t; s > 0; s -= 1)
        for (var c = !0; P(r[s] - r[s - 1]) && c; ) {
          var C = N(r, -1, s - 1);
          r[s - 1] = C.value, c = C.changed;
        }
      for (var m = r.length - 1; m > 0; m -= 1)
        for (var j = !0; P(r[m] - r[m - 1]) && j; ) {
          var q = N(r, -1, m - 1);
          r[m - 1] = q.value, j = q.changed;
        }
      for (var w = 0; w < r.length - 1; w += 1)
        for (var z = !0; P(r[w + 1] - r[w]) && z; ) {
          var B = N(r, 1, w + 1);
          r[w + 1] = B.value, z = B.changed;
        }
    }
    return {
      value: r[t],
      values: r
    };
  };
  return [A, H];
}
export {
  Q as default
};
