import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { BindingError } from "@contember/react-binding";
import { assertNever } from "@contember/utilities";
import { editorTemplateAnalyzer, BoxedContentOutletProps, BoxedCatchAllJSX } from "./editorTemplateAnalyzer.js";
const getEditorTemplate = (blockContents, env) => {
  let contentOutlet = void 0;
  const processed = editorTemplateAnalyzer.processChildren(blockContents, env);
  const nodesBefore = [];
  const nodesAfter = [];
  let currentTarget = nodesBefore;
  for (const node of processed) {
    if (node instanceof BoxedContentOutletProps) {
      if (contentOutlet === void 0) {
        contentOutlet = node.value;
        currentTarget = nodesAfter;
      } else {
        throw new BindingError(`BlockEditor: There must be no more than one ContentOutlet per block!`);
      }
    } else if (node instanceof BoxedCatchAllJSX) {
      currentTarget.push(node.value);
    } else {
      assertNever(node);
    }
  }
  if (contentOutlet === void 0) {
    return void 0;
  }
  return {
    blockContent: {
      nodeBefore: nodesBefore.length ? /* @__PURE__ */ jsxDEV(Fragment, { children: nodesBefore }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/templating/getEditorTemplate.tsx",
        lineNumber: 47,
        columnNumber: 37
      }, void 0) : void 0,
      value: contentOutlet,
      nodeAfter: nodesAfter.length ? /* @__PURE__ */ jsxDEV(Fragment, { children: nodesAfter }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/templating/getEditorTemplate.tsx",
        lineNumber: 49,
        columnNumber: 35
      }, void 0) : void 0
    }
  };
};
export {
  getEditorTemplate
};
//# sourceMappingURL=getEditorTemplate.js.map
