"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 convert_inline_styles_to_css_exports = {};
__export(convert_inline_styles_to_css_exports, {
  convertInlineStylesToCSS: () => convertInlineStylesToCSS
});
module.exports = __toCommonJS(convert_inline_styles_to_css_exports);
var import_lodash = __toESM(require("lodash"));
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_theme_color_token = require("./../../_shared/theme-color-token.js");
const convertDecorationsToCSS = (decorations) => {
  let draftBlockStyles = {};
  decorations?.forEach((decoration) => {
    const ricosDecortationFn = ricosDecorationToCss[decoration.type];
    let ricosDecoration = {};
    if (import_lodash.default.isFunction(ricosDecortationFn)) {
      ricosDecoration = ricosDecortationFn(decoration);
    }
    decoration && (draftBlockStyles = {
      ...draftBlockStyles,
      ...ricosDecoration
    });
  });
  return draftBlockStyles;
};
const ricosDecorationToCss = {
  [import_v1.Decoration_Type.FONT_FAMILY]: ({ fontFamilyData }) => {
    return fontFamilyData ? { "font-family": fontFamilyData.value } : {};
  },
  [import_v1.Decoration_Type.BOLD]: ({ fontWeightValue }) => {
    return fontWeightValue ? { "font-weight": fontWeightValue >= 700 ? "bold" : "normal" } : {};
  },
  [import_v1.Decoration_Type.ITALIC]: ({ italicData }) => {
    return typeof italicData !== "undefined" ? { "font-style": italicData ? "italic" : "normal" } : {};
  },
  [import_v1.Decoration_Type.UNDERLINE]: ({ underlineData }) => {
    return typeof underlineData !== "undefined" ? {
      "text-decoration": underlineData ? "underline" : "none"
    } : {};
  },
  [import_v1.Decoration_Type.FONT_SIZE]: ({ fontSizeData }) => {
    return fontSizeData ? { "font-size": fontSizeData.value + (fontSizeData.unit.toLowerCase() || "px") } : {};
  },
  [import_v1.Decoration_Type.STRIKETHROUGH]: ({ strikethroughData }) => {
    return typeof strikethroughData !== "undefined" ? {
      "text-decoration": strikethroughData ? "line-through" : "none"
    } : {};
  },
  [import_v1.Decoration_Type.COLOR]: ({ colorData }) => {
    return typeof colorData !== "undefined" ? {
      color: (0, import_theme_color_token.resolveDocumentColorToCss)(colorData.foreground),
      "background-color": (0, import_theme_color_token.resolveDocumentColorToCss)(colorData.background)
    } : {};
  },
  [import_v1.Decoration_Type.LINK]: () => ({}),
  [import_v1.Decoration_Type.ANCHOR]: () => ({}),
  [import_v1.Decoration_Type.SPOILER]: () => ({}),
  [import_v1.Decoration_Type.MENTION]: () => ({}),
  [import_v1.Decoration_Type.SUPERSCRIPT]: ({ superscriptData }) => {
    return typeof superscriptData !== "undefined" ? {
      "vertical-align": superscriptData ? "super" : "none"
    } : {};
  },
  [import_v1.Decoration_Type.SUBSCRIPT]: ({ subscriptData }) => {
    return typeof subscriptData !== "undefined" ? {
      "vertical-align": subscriptData ? "sub" : "none"
    } : {};
  },
  [import_v1.Decoration_Type.EXTERNAL]: () => ({}),
  [import_v1.Decoration_Type.SKETCH]: () => ({}),
  [import_v1.Decoration_Type.UNRECOGNIZED]: () => ({})
};
const convertNodeStyleToCss = (nodeStyle) => {
  return {
    ...nodeStyle.paddingTop && { "padding-top": nodeStyle.paddingTop },
    ...nodeStyle.paddingBottom && { "padding-bottom": nodeStyle.paddingBottom },
    ...nodeStyle.lineHeight && { "line-height": nodeStyle.lineHeight }
  };
};
const convertInlineStylesToCSS = (node) => {
  if ([import_v1.Node_Type.PARAGRAPH, import_v1.Node_Type.HEADING].includes(node.type)) {
    const nodeStyle = node.style;
    const { lineHeight } = node.paragraphData?.textStyle || node.headingData?.textStyle || {};
    const styles = (node.nodes ?? []).reduce((prevStyles, currentNode) => {
      return {
        ...prevStyles,
        ...convertDecorationsToCSS(currentNode.textData?.decorations)
      };
    }, {});
    return { ...styles, ...convertNodeStyleToCss({ ...nodeStyle, lineHeight }) };
  }
  return {};
};
//# sourceMappingURL=convert-inline-styles-to-css.js.map
