import lodash from "lodash";
import { createColorPalette, createPalette } from "../themeStrategy/generators/palette.js";
import { CustomStyle } from "./custom-style.js";
import { EmptyCustomStyle } from "./empty-custom-style.js";
const textCustomStylesKeys = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "quote", "codeBlock"];
const _CustomStyles = class _CustomStyles {
  constructor(customStyles) {
    this.customStyles = customStyles;
  }
  static of(rawCustomStyles) {
    const customStyles = Object.entries(rawCustomStyles).map(
      ([key, value]) => new CustomStyle(key, value)
    );
    return new _CustomStyles(customStyles);
  }
  static fromTheme(theme) {
    const customStyles = theme.customStyles || {};
    const { colors } = theme.colorPalette ? createColorPalette(theme.colorPalette, theme.paletteConfig) : createPalette(theme.palette, theme.paletteConfig);
    const { textColor: color, bgColor: backgroundColor } = colors || {};
    if (colors?.textColor || colors?.bgColor) {
      const colorsCustomStyles = textCustomStylesKeys.reduce(
        (acc, key) => ({ ...acc, [key]: { color, backgroundColor } }),
        {}
      );
      return _CustomStyles.of(colorsCustomStyles).overrideWith(_CustomStyles.of(customStyles));
    }
    return _CustomStyles.of(customStyles);
  }
  toCustomStyles() {
    return this.customStyles.reduce((acc, style) => {
      const customStyle = style.toCustomStyle();
      return {
        ...acc,
        ...!lodash.isEmpty(customStyle) ? { [style.getKey()]: customStyle } : {}
      };
    }, {});
  }
  byKey(key) {
    return this.customStyles.find((style) => style.getKey() === key) || _CustomStyles.empty;
  }
  overrideWith(customStyles) {
    const genericCustomStyles = textCustomStylesKeys.reduce(
      (acc, key) => ({ ...acc, [key]: {} }),
      {}
    );
    const overridenCustomStyles = _CustomStyles.of(genericCustomStyles).customStyles.map(
      (style) => style.overrideWith(this.byKey(style.getKey())).overrideWith(customStyles.byKey(style.getKey()))
    );
    return new _CustomStyles(overridenCustomStyles);
  }
};
_CustomStyles.empty = new EmptyCustomStyle();
let CustomStyles = _CustomStyles;
export {
  CustomStyles
};
//# sourceMappingURL=custom-styles.js.map
