import { __values as y } from "../../../../../tslib/tslib.es6.es.js";
import * as l from "react";
import { useMemo as a } from "react";
import { PresenceContext as E } from "../../context/PresenceContext.es.js";
import { useConstant as P } from "../../utils/use-constant.es.js";
import { useId as w } from "../../utils/use-id.es.js";
var k = function(r) {
  var c = r.children, m = r.initial, n = r.isPresent, t = r.onExitComplete, v = r.custom, d = r.presenceAffectsLayout, e = P(M), p = w(), x = a(
    function() {
      return {
        id: p,
        initial: m,
        isPresent: n,
        custom: v,
        onExitComplete: function(i) {
          var o, s;
          e.set(i, !0);
          try {
            for (var f = y(e.values()), u = f.next(); !u.done; u = f.next()) {
              var C = u.value;
              if (!C)
                return;
            }
          } catch (h) {
            o = { error: h };
          } finally {
            try {
              u && !u.done && (s = f.return) && s.call(f);
            } finally {
              if (o)
                throw o.error;
            }
          }
          t == null || t();
        },
        register: function(i) {
          return e.set(i, !1), function() {
            return e.delete(i);
          };
        }
      };
    },
    d ? void 0 : [n]
  );
  return a(function() {
    e.forEach(function(i, o) {
      return e.set(o, !1);
    });
  }, [n]), l.useEffect(function() {
    !n && !e.size && (t == null || t());
  }, [n]), l.createElement(E.Provider, { value: x }, c);
};
function M() {
  return /* @__PURE__ */ new Map();
}
export {
  k as PresenceChild
};
//# sourceMappingURL=PresenceChild.es.js.map
