"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ricos_content_analytics_exports = {};
__export(ricos_content_analytics_exports, {
  getContentSummary: () => getContentSummary
});
module.exports = __toCommonJS(ricos_content_analytics_exports);
var import_lodash = __toESM(require("lodash"));
var import_ricos_content = require("./../../ricos-content/index.js");
var import_extract = require("./../../ricos-content/lib/extract.js");
var import_utils = require("./../../ricos-content/TranslatableAPI/utils.js");
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
const countByType = (obj) => import_lodash.default.countBy(obj, (x) => x.type);
const TO_PLUGIN_TYPE = {
  [import_v1.Node_Type.DIVIDER]: import_ricos_content.DIVIDER_TYPE,
  [import_v1.Node_Type.IMAGE]: import_ricos_content.IMAGE_TYPE,
  [import_v1.Node_Type.GALLERY]: import_ricos_content.GALLERY_TYPE,
  [import_v1.Node_Type.GIF]: import_ricos_content.GIPHY_TYPE,
  [import_v1.Node_Type.HTML]: import_ricos_content.HTML_TYPE,
  [import_v1.Node_Type.VIDEO]: import_ricos_content.VIDEO_TYPE,
  [import_v1.Node_Type.FILE]: import_ricos_content.FILE_UPLOAD_TYPE,
  [import_v1.Node_Type.POLL]: import_ricos_content.POLL_TYPE,
  [import_v1.Node_Type.COLLAPSIBLE_LIST]: import_ricos_content.COLLAPSIBLE_LIST_TYPE,
  [import_v1.Node_Type.TABLE]: import_ricos_content.TABLE_TYPE,
  [import_v1.Node_Type.EMBED]: import_ricos_content.LINK_PREVIEW_TYPE,
  [import_v1.Node_Type.LINK_PREVIEW]: import_ricos_content.LINK_PREVIEW_TYPE,
  [import_v1.Node_Type.APP_EMBED]: import_ricos_content.APP_EMBED_TYPE,
  [import_v1.Node_Type.AUDIO]: import_ricos_content.AUDIO_TYPE,
  [import_v1.Node_Type.BUTTON]: import_ricos_content.LINK_BUTTON_TYPE,
  [import_v1.Node_Type.CODE_BLOCK]: import_ricos_content.CODE_BLOCK_TYPE,
  [import_v1.Node_Type.BLOCKQUOTE]: import_ricos_content.BLOCKQUOTE
};
const headingLevelToTag = {
  1: "header-one",
  2: "header-two",
  3: "header-three",
  4: "header-four",
  5: "header-five",
  6: "header-six"
};
const DECORATION_TO_NODE_TYPE = {
  [import_v1.Decoration_Type.MENTION]: import_ricos_content.MENTION_TYPE,
  [import_v1.Decoration_Type.LINK]: import_ricos_content.LINK_TYPE,
  [import_v1.Decoration_Type.ANCHOR]: import_ricos_content.ANCHOR_TYPE
};
const emojiRegex = /\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/g;
function getContentSummary(content) {
  const { nodes } = content;
  const plugins = (0, import_extract.extract)(nodes ?? []).filter(
    (node) => ![
      import_v1.Node_Type.PARAGRAPH,
      import_v1.Node_Type.TEXT,
      import_v1.Node_Type.UNRECOGNIZED,
      import_v1.Node_Type.COLLAPSIBLE_ITEM,
      import_v1.Node_Type.COLLAPSIBLE_ITEM_BODY,
      import_v1.Node_Type.COLLAPSIBLE_ITEM_TITLE,
      import_v1.Node_Type.TABLE_CELL,
      import_v1.Node_Type.TABLE_ROW
    ].includes(node.type)
  ).map((node) => {
    const { type } = node;
    const data = (0, import_utils.getDataFieldValue)(node);
    const details = {};
    const plugin_type = TO_PLUGIN_TYPE[type] || type === import_v1.Node_Type.HEADING && headingLevelToTag[data?.level];
    if (plugin_type) {
      details.type = plugin_type;
      if (data) {
        details.data = data;
      }
    }
    return details;
  }).filter((node) => !!node.type).get();
  const decorations = (0, import_extract.extract)(nodes ?? []).filter((node) => {
    return !!node.textData?.decorations?.some(
      (decoration) => [import_v1.Decoration_Type.ANCHOR, import_v1.Decoration_Type.LINK, import_v1.Decoration_Type.MENTION].includes(
        decoration.type
      )
    );
  }).map((node) => {
    const data = node.textData?.decorations?.find(
      (decoration) => DECORATION_TO_NODE_TYPE[decoration.type]
    );
    const details = {};
    const plugin_type = data?.type && DECORATION_TO_NODE_TYPE[data.type];
    if (plugin_type) {
      details.type = plugin_type;
      if (data) {
        details.data = (0, import_utils.getDataFieldValue)(node);
      }
    }
    return details;
  }).filter((node) => !!node.type).get();
  const emoji = (0, import_extract.extract)(nodes ?? []).map(({ textData }) => textData?.text || "").get().reduce((acc, text) => {
    return acc + (text.match(emojiRegex) || []).length;
  }, 0);
  return {
    pluginsCount: {
      ...countByType(plugins),
      ...countByType(decorations),
      [import_ricos_content.EMOJI_TYPE]: emoji
    },
    pluginsDetails: [...plugins, ...decorations]
  };
}
//# sourceMappingURL=ricos-content-analytics.js.map
