import lodash from "lodash";
import { Decoration_Type } from "./../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { EmptyDecoration } from "./empty-decoration.js";
class ColorDecoration {
  constructor(customStyle) {
    this.type = Decoration_Type.COLOR;
    this.customStyle = customStyle;
  }
  static of(decoration) {
    if (decoration.type !== Decoration_Type.COLOR) {
      throw new TypeError(`invalid decoration initializer ${decoration}`);
    }
    const { foreground: color, background: backgroundColor } = decoration.colorData || {};
    const customStyle = lodash.pickBy({ color, backgroundColor });
    return new ColorDecoration(customStyle);
  }
  getDecoration() {
    return {
      type: this.type,
      colorData: {
        ...this.customStyle.color && { foreground: this.customStyle.color },
        ...this.customStyle.backgroundColor && { background: this.customStyle.backgroundColor }
      }
    };
  }
  static fromCustomStyle(customStyle) {
    return new ColorDecoration(customStyle);
  }
  fromCustomStyle(customStyle) {
    return ColorDecoration.fromCustomStyle(customStyle);
  }
  toCustomStyle() {
    return this.customStyle;
  }
  overrideWith(decoration) {
    if (!(decoration instanceof ColorDecoration || decoration instanceof EmptyDecoration)) {
      throw new TypeError(`invalid merge decoration ${decoration}`);
    }
    const customStyle = { ...this.customStyle, ...decoration.toCustomStyle() };
    return new ColorDecoration(customStyle);
  }
}
export {
  ColorDecoration
};
//# sourceMappingURL=color-decoration.js.map
