import { jsx as a } from "react/jsx-runtime";
import * as M from "react";
import { useId as w, useMemo as c } from "react";
import { PresenceContext as x } from "../../context/PresenceContext.es.js";
import { useConstant as R } from "../../utils/use-constant.es.js";
import { PopChild as g } from "./PopChild.es.js";
const _ = ({ children: n, initial: p, isPresent: r, onExitComplete: o, custom: i, presenceAffectsLayout: m, mode: l, anchorX: d, anchorY: h, root: C }) => {
  const e = R(j), v = w();
  let u = !0, s = c(() => (u = !1, {
    id: v,
    initial: p,
    isPresent: r,
    custom: i,
    onExitComplete: (t) => {
      e.set(t, !0);
      for (const f of e.values())
        if (!f)
          return;
      o && o();
    },
    register: (t) => (e.set(t, !1), () => e.delete(t))
  }), [r, e, o]);
  return m && u && (s = { ...s }), c(() => {
    e.forEach((t, f) => e.set(f, !1));
  }, [r]), M.useEffect(() => {
    !r && !e.size && o && o();
  }, [r]), n = a(g, { pop: l === "popLayout", isPresent: r, anchorX: d, anchorY: h, root: C, children: n }), a(x.Provider, { value: s, children: n });
};
function j() {
  return /* @__PURE__ */ new Map();
}
export {
  _ as PresenceChild
};
//# sourceMappingURL=PresenceChild.es.js.map
