import { useContext, useId, useEffect, useCallback } from "react";
import { PresenceContext } from "../../context/PresenceContext.js";
function usePresence(subscribe = true) {
  const context = useContext(PresenceContext);
  if (context === null)
    return [true, null];
  const { isPresent, onExitComplete, register } = context;
  const id = useId();
  useEffect(() => {
    if (subscribe) {
      return register(id);
    }
  }, [subscribe]);
  const safeToRemove = useCallback(() => subscribe && onExitComplete && onExitComplete(id), [id, onExitComplete, subscribe]);
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
}
export {
  usePresence
};
//# sourceMappingURL=use-presence.js.map
