import $ from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import s from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as r from "react";
import d from "../../../rc-util/es/hooks/useLayoutEffect.mjs";
import h from "../../../rc-util/es/Dom/canUseDom.mjs";
import y from "./Context.mjs";
var p = [];
function T(o, f) {
  var v = r.useState(function() {
    if (!h())
      return null;
    var e = document.createElement("div");
    return process.env.NODE_ENV !== "production" && f && e.setAttribute("data-debug", f), e;
  }), E = s(v, 1), t = E[0], n = r.useRef(!1), u = r.useContext(y), _ = r.useState(p), i = s(_, 2), a = i[0], c = i[1], C = u || (n.current ? void 0 : function(e) {
    c(function(R) {
      var S = [e].concat($(R));
      return S;
    });
  });
  function l() {
    t.parentElement || document.body.appendChild(t), n.current = !0;
  }
  function m() {
    var e;
    (e = t.parentElement) === null || e === void 0 || e.removeChild(t), n.current = !1;
  }
  return d(function() {
    return o ? u ? u(l) : l() : m(), m;
  }, [o]), d(function() {
    a.length && (a.forEach(function(e) {
      return e();
    }), c(p));
  }, [a]), [t, C];
}
export {
  T as default
};
