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