import P from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import g from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as y from "react";
import { useRef as s, useCallback as u } from "react";
import { warningOnce as A } from "../../../rc-util/es/warning.mjs";
import { nextSlice as U } from "../utils/timeUtil.mjs";
var p = "__RC_UTIL_PATH_SPLIT__", K = function(c) {
  return c.join(p);
}, $ = function(c) {
  return c.split(p);
}, m = "rc-menu-more";
function D() {
  var i = y.useState({}), c = g(i, 2), S = c[1], a = s(/* @__PURE__ */ new Map()), o = s(/* @__PURE__ */ new Map()), _ = y.useState([]), d = g(_, 2), f = d[0], R = d[1], v = s(0), l = s(!1), w = function() {
    l.current || S({});
  }, b = u(function(e, t) {
    process.env.NODE_ENV !== "production" && A(!a.current.has(e), "Duplicated key '".concat(e, "' used in Menu by path [").concat(t.join(" > "), "]"));
    var r = K(t);
    o.current.set(r, e), a.current.set(e, r), v.current += 1;
    var n = v.current;
    U(function() {
      n === v.current && w();
    });
  }, []), O = u(function(e, t) {
    var r = K(t);
    o.current.delete(r), a.current.delete(e);
  }, []), E = u(function(e) {
    R(e);
  }, []), h = u(function(e, t) {
    var r = a.current.get(e) || "", n = $(r);
    return t && f.includes(n[0]) && n.unshift(m), n;
  }, [f]), T = u(function(e, t) {
    return e.some(function(r) {
      var n = h(r, !0);
      return n.includes(t);
    });
  }, [h]), L = function() {
    var t = P(a.current.keys());
    return f.length && t.push(m), t;
  }, k = u(function(e) {
    var t = "".concat(a.current.get(e)).concat(p), r = /* @__PURE__ */ new Set();
    return P(o.current.keys()).forEach(function(n) {
      n.startsWith(t) && r.add(o.current.get(n));
    }), r;
  }, []);
  return y.useEffect(function() {
    return function() {
      l.current = !0;
    };
  }, []), {
    // Register
    registerPath: b,
    unregisterPath: O,
    refreshOverflowKeys: E,
    // Util
    isSubPathKey: T,
    getKeyPath: h,
    getKeys: L,
    getSubPathKeys: k
  };
}
export {
  m as OVERFLOW_KEY,
  D as default
};
