import { jsx as a } from "react/jsx-runtime";
import * as C from "react";
import { useId as v, useMemo as c } from "react";
import { PresenceContext as M } from "../../context/PresenceContext.js";
import { useConstant as w } from "../../utils/use-constant.js";
import { PopChild as x } from "./PopChild.js";
const X = ({ children: f, initial: i, isPresent: r, onExitComplete: t, custom: m, presenceAffectsLayout: p, mode: l, anchorX: d }) => {
  const e = w(R), h = v();
  let u = !0, s = c(() => (u = !1, {
    id: h,
    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]), C.useEffect(() => {
    !r && !e.size && t && t();
  }, [r]), l === "popLayout" && (f = a(x, { isPresent: r, anchorX: d, children: f })), a(M.Provider, { value: s, children: f });
};
function R() {
  return /* @__PURE__ */ new Map();
}
export {
  X as PresenceChild
};
//# sourceMappingURL=PresenceChild.js.map
