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