"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const reactBinding = require("@contember/react-binding");
const react = require("react");
const reactUtils = require("@contember/react-utils");
const useGetReferenceEntityList = ({
  referencesField,
  sortedBlocksRef,
  monolithicReferencesMode
}) => {
  reactUtils.useConstantValueInvariant(referencesField);
  reactUtils.useConstantValueInvariant(monolithicReferencesMode);
  if (!referencesField) {
    return react.useCallback(() => {
      throw new reactBinding.BindingError(
        `BlockEditor: trying to get or insert a referenced element but referencing has not been correctly set up. Check the BlockEditor props.`
      );
    }, []);
  }
  return monolithicReferencesMode ? useGetMonolithicReferenceList({ referencesField }) : useGetPerBlockReferenceList({ referencesField, sortedBlocksRef });
};
const useGetMonolithicReferenceList = ({ referencesField }) => {
  const referenceList = reactBinding.useEntityList(referencesField);
  return react.useCallback(() => referenceList, [referenceList]);
};
const useGetPerBlockReferenceList = ({ referencesField, sortedBlocksRef }) => {
  return react.useCallback((targetPath) => {
    const blockIndex = targetPath[0];
    const containingBlock = sortedBlocksRef.current[blockIndex];
    if (!containingBlock) {
      throw new reactBinding.BindingError();
    }
    return containingBlock.getEntityList(referencesField);
  }, [referencesField, sortedBlocksRef]);
};
exports.useGetReferenceEntityList = useGetReferenceEntityList;
//# sourceMappingURL=useGetReferenceEntityList.cjs.map
