import { NodeAnnotation, NodeAnnotationTypeEnum } from './node-annotation.abstract';
import { RTE_TEXT_COLORS } from '../../constants/constant';
import { VegaInternalThemeManager } from '../../../../helpers/theme/internal-theme-manager';
/**
 * Annotation to make text with text color
 */
export class TextColorAnnotation extends NodeAnnotation {
  constructor(textColor) {
    super();
    this.type = NodeAnnotationTypeEnum.TEXT_COLOR;
    this.textColor = this.formatTextColor(textColor);
  }
  /**
   * Generate the map item for the annotation
   *
   * @param {string} textColor - text color annotation
   * @returns {[NodeAnnotationTypeEnum.TEXT_COLOR, TextColorAnnotation]} Map item for the annotation
   */
  static from(textColor) {
    return [NodeAnnotationTypeEnum.TEXT_COLOR, new TextColorAnnotation(textColor)];
  }
  /**
   * Generate the JSON representation of the annotation
   *
   * @returns {Record<string, unknown>} JSON representation of the annotation
   */
  toJSON() {
    return {
      textColor: this.textColor.key,
    };
  }
  /**
   * @inheritDoc
   */
  clone() {
    return new TextColorAnnotation(this.textColor.key);
  }
  /**
   * @inheritDoc
   */
  renderClass() {
    return null;
  }
  /**
   * @inheritDoc
   */
  renderStyle() {
    return {
      color: VegaInternalThemeManager.isDarkMode() ? this.textColor.dark : this.textColor.light,
    };
  }
  /**
   * format text color
   *
   * @param {string} textColor - text color
   * @returns {VegaRTEColorSchema} - VegaRTEColorSchema
   */
  formatTextColor(textColor) {
    return (RTE_TEXT_COLORS.find((item) => item.key === textColor) || RTE_TEXT_COLORS[0]);
  }
}
