import { Node_Type } from "./../../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { ensureNodeType, toHtml } from "../../converters/html/toHtml/to-html.js";
import { firstRight } from "../../fp-utils.js";
import { extract } from "../../RicosContentAPI/extract.js";
import { getDataFieldName, getDataFieldValue, isType } from "../utils.js";
import { fieldsToTranslatables } from "./fields-to-translatables.js";
import {
  toAppEmbedTranslatable,
  toButtonTranslatable,
  toGalleryTranslatable,
  toHtmlTranslatable,
  toImageTranslatable,
  toLinkPreviewTranslatable,
  toPollTranslatable,
  toVideoTranslatable
} from "./plugins-to-translatables.js";
const toTranslatables = ({ nodes }) => {
  const nodesWithType = ensureNodeType(nodes ?? []);
  return [
    ...nodeDataTranslatables(nodesWithType),
    ...nodeContainerDataTranslatables(nodesWithType)
  ];
};
const nodeDataTranslatables = (nodes) => extract(nodes).map(
  (node) => firstRight(node, [], [
    [isType(Node_Type.HEADING), getTextualContent],
    [isType(Node_Type.PARAGRAPH), getTextualContent],
    [isType(Node_Type.APP_EMBED), toAppEmbedTranslatable],
    [isType(Node_Type.BUTTON), toButtonTranslatable],
    [isType(Node_Type.GALLERY), toGalleryTranslatable],
    [isType(Node_Type.HTML), toHtmlTranslatable],
    [isType(Node_Type.IMAGE), toImageTranslatable],
    [
      isType(Node_Type.LINK_PREVIEW),
      toLinkPreviewTranslatable
    ],
    [isType(Node_Type.POLL), toPollTranslatable],
    [isType(Node_Type.VIDEO), toVideoTranslatable]
  ])
).get().flat();
const nodeContainerDataTranslatables = (nodes) => extract(nodes).filter((node) => "containerData" in (getDataFieldValue(node) ?? {})).map((node) => {
  const pluginData = getDataFieldName(node);
  return [
    ...fieldsToTranslatables(node, [
      pluginData,
      "containerData",
      "spoiler",
      "buttonText"
    ]),
    ...fieldsToTranslatables(node, [
      pluginData,
      "containerData",
      "spoiler",
      "description"
    ])
  ];
}).get().flat();
const getTextualContent = (node) => {
  const { id, type } = node;
  const textNodes = extract(node).filter(({ nodes }) => (nodes?.length ?? 0) > 0).get();
  if (textNodes.length === 0) {
    return [];
  }
  return [
    {
      id,
      type,
      text: toHtml({
        nodes: textNodes
      })
    }
  ];
};
export {
  toTranslatables
};
//# sourceMappingURL=to-translatables.js.map
