import { createElement, Fragment } from "react";
import { BindingError } from "@contember/binding";
import { editorTemplateAnalyzer, BoxedContentOutletProps, BoxedCatchAllJSX } from "./editorTemplateAnalyzer.js";
import { assertNever } from "../../../../../utils/assertNever.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();
    }
  }
  if (contentOutlet === void 0) {
    return void 0;
  }
  return {
    blockContent: {
      nodeBefore: nodesBefore.length ? /* @__PURE__ */ createElement(Fragment, null, nodesBefore) : void 0,
      value: contentOutlet,
      nodeAfter: nodesAfter.length ? /* @__PURE__ */ createElement(Fragment, null, nodesAfter) : void 0
    }
  };
};
export { getEditorTemplate };
//# sourceMappingURL=getEditorTemplate.js.map
