"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var to_plain_text_base_exports = {};
__export(to_plain_text_base_exports, {
  toPlainTextBase: () => toPlainTextBase
});
module.exports = __toCommonJS(to_plain_text_base_exports);
var import_v1 = require("./../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_decoration_parsers = require("../../draft/toDraft/decoration-parsers.js");
var import_convert_nodes = require("./convert-nodes.js");
function* parseCollapsible(node, delimiter) {
  const collapsibleTextNodes = [];
  for (const child of node.nodes ?? []) {
    const [first, second] = child.nodes ?? [];
    if (!first || !second) {
      continue;
    }
    collapsibleTextNodes.push(
      [yield* toPlainTextBase(first), yield* toPlainTextBase(second)].join(delimiter)
    );
  }
  return collapsibleTextNodes.join(delimiter);
}
function* toPlainTextBase(content, delimiter = "\n", addLinksToText = true) {
  const ricosContent = import_v1.RichContent.fromJSON(content);
  const { nodes = [] } = ricosContent;
  let plainText = "";
  let index = 0;
  while (nodes.length) {
    const node = nodes.shift();
    if (node) {
      if (index > 0) {
        plainText += delimiter;
      }
      index++;
      switch (node.type) {
        case import_v1.Node_Type.CODE_BLOCK:
        case import_v1.Node_Type.PARAGRAPH:
        case import_v1.Node_Type.HEADING:
          plainText += (0, import_convert_nodes.parseTextNodes)(node, addLinksToText);
          break;
        case import_v1.Node_Type.BLOCKQUOTE:
          plainText += (0, import_convert_nodes.parseTextNodes)((0, import_decoration_parsers.getParagraphNode)(node), addLinksToText);
          break;
        case import_v1.Node_Type.ORDERED_LIST:
        case import_v1.Node_Type.BULLETED_LIST:
        case import_v1.Node_Type.CHECKBOX_LIST:
          plainText += (0, import_convert_nodes.parseListNode)(node, delimiter, addLinksToText);
          break;
        case import_v1.Node_Type.GIF:
          plainText += yield* (0, import_convert_nodes.parseGiphy)(node);
          break;
        case import_v1.Node_Type.APP_EMBED:
          plainText += (0, import_convert_nodes.parseAppEmbed)(node, delimiter);
          break;
        case import_v1.Node_Type.LINK_PREVIEW:
          plainText += (0, import_convert_nodes.parseLinkPreview)(node);
          break;
        case import_v1.Node_Type.EMBED:
          plainText += (0, import_convert_nodes.parseEmbed)(node);
          break;
        case import_v1.Node_Type.IMAGE:
          plainText += yield* (0, import_convert_nodes.parseImage)(node, delimiter);
          break;
        case import_v1.Node_Type.VIDEO:
          plainText += yield* (0, import_convert_nodes.parseVideo)(node, delimiter);
          break;
        case import_v1.Node_Type.AUDIO:
          plainText += yield* (0, import_convert_nodes.parseAudio)(node, delimiter);
          break;
        case import_v1.Node_Type.COLLAPSIBLE_LIST:
          plainText += yield* parseCollapsible(node, delimiter);
          break;
        case import_v1.Node_Type.LAYOUT: {
          const layoutCellsContent = node.nodes.map((cell) => cell.nodes).flat();
          nodes.unshift(...layoutCellsContent);
          index--;
          break;
        }
        default:
      }
    }
  }
  return plainText;
}
//# sourceMappingURL=to-plain-text-base.js.map
