import { pipe } from "fp-ts-esm/function";
import lodash from "lodash";
import { generateId } from "../converters/generate-random-id.js";
import { setupContentBuilder } from "../RicosContentAPI/ricos-content-builder.js";
import { applyContent } from "./consts.js";
import { addImage } from "./nativeElements/add-image.js";
const extractBuilderMethods = ({ RicosContentBuilder: _, ...rest }) => rest;
const notify = (content, callback) => {
  callback?.(content);
  return createBuilder(content, callback);
};
const applyBuilderPattern = (content, callback) => (methods) => Object.entries(methods).reduce(
  (prev, [key, func]) => ({
    ...prev,
    [key]: lodash.flow(
      applyContent(content),
      func,
      (newContent) => notify(newContent, callback)
    )
  }),
  {}
);
const createBuilder = (content, callback) => {
  const originalMethods = pipe(generateId, setupContentBuilder, extractBuilderMethods);
  const adapterMethods = pipe(originalMethods, applyBuilderPattern(content, callback));
  return {
    ...adapterMethods,
    addImage: lodash.flow(
      addImage,
      applyContent(content),
      originalMethods.addImage,
      (newContent) => notify(newContent, callback)
    ),
    get: () => content
  };
};
export {
  createBuilder
};
//# sourceMappingURL=builder-old.js.map
