import w from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import a from "../../../rc-util/es/KeyCode.mjs";
import g from "../../../rc-util/es/raf.mjs";
import h from "../../../rc-util/es/Dom/isVisible.mjs";
var c = /* @__PURE__ */ new Map();
function N(r, e) {
  var t;
  function o() {
    h(r) ? e() : t = g(function() {
      o();
    });
  }
  return o(), function() {
    g.cancel(t);
  };
}
function v(r, e, t) {
  if (c.get(r) && cancelAnimationFrame(c.get(r)), t <= 0) {
    c.set(r, requestAnimationFrame(function() {
      r.scrollTop = e;
    }));
    return;
  }
  var o = e - r.scrollTop, n = o / t * 10;
  c.set(r, requestAnimationFrame(function() {
    r.scrollTop += n, r.scrollTop !== e && v(r, e, t - 10);
  }));
}
function F(r, e) {
  var t = e.onLeftRight, o = e.onCtrlLeftRight, n = e.onUpDown, u = e.onPageUpDown, s = e.onEnter, m = r.which, l = r.ctrlKey, d = r.metaKey;
  switch (m) {
    case a.LEFT:
      if (l || d) {
        if (o)
          return o(-1), !0;
      } else if (t)
        return t(-1), !0;
      break;
    case a.RIGHT:
      if (l || d) {
        if (o)
          return o(1), !0;
      } else if (t)
        return t(1), !0;
      break;
    case a.UP:
      if (n)
        return n(-1), !0;
      break;
    case a.DOWN:
      if (n)
        return n(1), !0;
      break;
    case a.PAGE_UP:
      if (u)
        return u(-1), !0;
      break;
    case a.PAGE_DOWN:
      if (u)
        return u(1), !0;
      break;
    case a.ENTER:
      if (s)
        return s(), !0;
      break;
  }
  return !1;
}
function T(r, e, t, o) {
  var n = r;
  if (!n)
    switch (e) {
      case "time":
        n = o ? "hh:mm:ss a" : "HH:mm:ss";
        break;
      case "week":
        n = "gggg-wo";
        break;
      case "month":
        n = "YYYY-MM";
        break;
      case "quarter":
        n = "YYYY-[Q]Q";
        break;
      case "year":
        n = "YYYY";
        break;
      default:
        n = t ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD";
    }
  return n;
}
function R(r, e, t) {
  var o = r === "time" ? 8 : 10, n = typeof e == "function" ? e(t.getNow()).length : e.length;
  return Math.max(o, n) + 2;
}
var i = null, f = /* @__PURE__ */ new Set();
function C(r) {
  return !i && typeof window < "u" && window.addEventListener && (i = function(t) {
    w(f).forEach(function(o) {
      o(t);
    });
  }, window.addEventListener("mousedown", i)), f.add(r), function() {
    f.delete(r), f.size === 0 && (window.removeEventListener("mousedown", i), i = null);
  };
}
function L(r) {
  var e = r.target;
  if (r.composed && e.shadowRoot) {
    var t;
    return ((t = r.composedPath) === null || t === void 0 ? void 0 : t.call(r)[0]) || e;
  }
  return e;
}
var k = function(e) {
  return e === "month" || e === "date" ? "year" : e;
}, Y = function(e) {
  return e === "date" ? "month" : e;
}, p = function(e) {
  return e === "month" || e === "date" ? "quarter" : e;
}, M = function(e) {
  return e === "date" ? "week" : e;
}, A = {
  year: k,
  month: Y,
  quarter: p,
  week: M,
  time: null,
  date: null
};
function H(r, e) {
  return r.some(function(t) {
    return t && t.contains(e);
  });
}
export {
  A as PickerModeMap,
  C as addGlobalMouseDownEvent,
  F as createKeyDownHandler,
  H as elementsContains,
  T as getDefaultFormat,
  R as getInputSize,
  L as getTargetFromEvent,
  v as scrollTo,
  N as waitElementReady
};
