import { useEffect } from "react";
import { useDispatch } from "./use-dispatch";
import { useIsInBuilder } from "./use-is-in-builder";
import { registerDocument, registerDocumentsEffect } from "../../../state/shared-api";
import { registerBuilderDocumentsEffect } from "../../../state/builder-api/actions";
import { isServer } from "../../../utils/is-server";
import { useIsomorphicLayoutEffect } from "../../../components/hooks/useIsomorphicLayoutEffect";
function useRegisterDocument(document) {
  const isInBuilder = useIsInBuilder();
  const dispatch = useDispatch();
  if (isServer()) {
    dispatch(registerDocument(document));
  }
  useIsomorphicLayoutEffect(() => {
    return dispatch(registerDocumentsEffect([document]));
  }, [dispatch, document]);
  useEffect(() => {
    if (!isInBuilder)
      return;
    return dispatch(registerBuilderDocumentsEffect([document]));
  }, [isInBuilder, document]);
}
export {
  useRegisterDocument
};
//# sourceMappingURL=use-register-document.js.map