import lodash from "lodash";
import { Decoration_Type, Node_Type } from "./../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { resolveDocumentColorToCss } from "./../../_shared/theme-color-token.js";
const convertDecorationsToCSS = (decorations) => {
  let draftBlockStyles = {};
  decorations?.forEach((decoration) => {
    const ricosDecortationFn = ricosDecorationToCss[decoration.type];
    let ricosDecoration = {};
    if (lodash.isFunction(ricosDecortationFn)) {
      ricosDecoration = ricosDecortationFn(decoration);
    }
    decoration && (draftBlockStyles = {
      ...draftBlockStyles,
      ...ricosDecoration
    });
  });
  return draftBlockStyles;
};
const ricosDecorationToCss = {
  [Decoration_Type.FONT_FAMILY]: ({ fontFamilyData }) => {
    return fontFamilyData ? { "font-family": fontFamilyData.value } : {};
  },
  [Decoration_Type.BOLD]: ({ fontWeightValue }) => {
    return fontWeightValue ? { "font-weight": fontWeightValue >= 700 ? "bold" : "normal" } : {};
  },
  [Decoration_Type.ITALIC]: ({ italicData }) => {
    return typeof italicData !== "undefined" ? { "font-style": italicData ? "italic" : "normal" } : {};
  },
  [Decoration_Type.UNDERLINE]: ({ underlineData }) => {
    return typeof underlineData !== "undefined" ? {
      "text-decoration": underlineData ? "underline" : "none"
    } : {};
  },
  [Decoration_Type.FONT_SIZE]: ({ fontSizeData }) => {
    return fontSizeData ? { "font-size": fontSizeData.value + (fontSizeData.unit.toLowerCase() || "px") } : {};
  },
  [Decoration_Type.STRIKETHROUGH]: ({ strikethroughData }) => {
    return typeof strikethroughData !== "undefined" ? {
      "text-decoration": strikethroughData ? "line-through" : "none"
    } : {};
  },
  [Decoration_Type.COLOR]: ({ colorData }) => {
    return typeof colorData !== "undefined" ? {
      color: resolveDocumentColorToCss(colorData.foreground),
      "background-color": resolveDocumentColorToCss(colorData.background)
    } : {};
  },
  [Decoration_Type.LINK]: () => ({}),
  [Decoration_Type.ANCHOR]: () => ({}),
  [Decoration_Type.SPOILER]: () => ({}),
  [Decoration_Type.MENTION]: () => ({}),
  [Decoration_Type.SUPERSCRIPT]: ({ superscriptData }) => {
    return typeof superscriptData !== "undefined" ? {
      "vertical-align": superscriptData ? "super" : "none"
    } : {};
  },
  [Decoration_Type.SUBSCRIPT]: ({ subscriptData }) => {
    return typeof subscriptData !== "undefined" ? {
      "vertical-align": subscriptData ? "sub" : "none"
    } : {};
  },
  [Decoration_Type.EXTERNAL]: () => ({}),
  [Decoration_Type.SKETCH]: () => ({}),
  [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 ([Node_Type.PARAGRAPH, 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 {};
};
export {
  convertInlineStylesToCSS
};
//# sourceMappingURL=convert-inline-styles-to-css.js.map
