import C from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as S from "react";
import { useRef as o, useEffect as _ } from "react";
import k from "../../../rc-util/es/Dom/findDOMNode.mjs";
import v from "../../../rc-util/es/raf.mjs";
import y from "../utils/CacheMap.mjs";
function O(R, n, c) {
  var h = S.useState(0), i = C(h, 2), M = i[0], H = i[1], f = o(/* @__PURE__ */ new Map()), u = o(new y()), s = o();
  function l() {
    v.cancel(s.current);
  }
  function d() {
    var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !1;
    l();
    var r = function() {
      f.current.forEach(function(e, p) {
        if (e && e.offsetParent) {
          var g = k(e), w = g.offsetHeight;
          u.current.get(p) !== w && u.current.set(p, g.offsetHeight);
        }
      }), H(function(e) {
        return e + 1;
      });
    };
    t ? r() : s.current = v(r);
  }
  function m(t, r) {
    var a = R(t), e = f.current.get(a);
    r ? (f.current.set(a, r), d()) : f.current.delete(a), !e != !r && (r ? n == null || n(t) : c == null || c(t));
  }
  return _(function() {
    return l;
  }, []), [m, d, u.current, M];
}
export {
  O as default
};
