import { Decoration_Type } from "./../../../../../ricos-schema/legacy/wix/rich_content/v1/index.js";
const convertDocumentStyleDecorationTypes = (decorations) => {
  let draftBlockStyles = {};
  decorations.forEach((decoration) => {
    decoration && (draftBlockStyles = {
      ...draftBlockStyles,
      ...ricosDecorationToCss[decoration.type](decoration)
    });
  });
  return draftBlockStyles;
};
const ricosDecorationToCss = {
  [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.COLOR]: ({ colorData }) => {
    const { foreground, background } = colorData;
    const colors = {};
    foreground && (colors["color"] = foreground);
    background && (colors["background-color"] = background);
    return colors;
  }
};
const convertNodeStyleToCss = (nodeStyle) => {
  const css = {};
  nodeStyle.paddingTop && (css["padding-top"] = nodeStyle.paddingTop);
  nodeStyle.paddingBottom && (css["padding-bottom"] = nodeStyle.paddingBottom);
  nodeStyle.lineHeight && (css["line-height"] = nodeStyle.lineHeight);
  return css;
};
const parseDocStyle = (documentStyle) => {
  const draftDocStyle = {};
  Object.entries(documentStyle).forEach(([header, values]) => {
    if (values) {
      const { decorations = [], nodeStyle, lineHeight } = values;
      draftDocStyle[header] = {
        ...convertDocumentStyleDecorationTypes(decorations),
        ...convertNodeStyleToCss({ ...nodeStyle, lineHeight })
      };
    }
  });
  return draftDocStyle;
};
export {
  parseDocStyle
};
//# sourceMappingURL=parse-doc-style.js.map
