import { VegaInternalThemeManager } from '../../../../../helpers/theme/internal-theme-manager';
import { BlockAnnotation } from '../../../dto/annotations/block-annotation.abstract';
import { RTETableColorManager } from '../utils/table-color-manager';
import { RTETableExtensionAnnotationTypeEnum } from './table-annotation';
/**
 * Class representing a table color annotation in the rich text editor.
 */
export class RTETableColorAnnotation extends BlockAnnotation {
  constructor(colorKey) {
    super();
    this.type = RTETableExtensionAnnotationTypeEnum.COLOR;
    this.colorKey = colorKey;
    if (colorKey) {
      this.color = this.formatColor(colorKey);
    }
  }
  /**
   * Render the style for the annotation
   *
   * @returns {AnnotationStyle} The style object containing the color
   */
  renderStyle() {
    const color = this.color
      ? VegaInternalThemeManager.isDarkMode()
        ? this.color.dark
        : this.color.light
      : this.colorKey || '';
    return { color };
  }
  /**
   * Render the CSS class for the annotation
   *
   * @returns {Nullable<string>} Always returns null as no CSS class is used
   */
  renderClass() {
    return null;
  }
  /**
   * Convert the annotation to a JSON representation
   *
   * @returns {Record<string, string>} A JSON object containing the color key
   */
  toJSON() {
    var _a;
    return {
      color: ((_a = this.color) === null || _a === void 0 ? void 0 : _a.key) || this.colorKey || '',
    };
  }
  /**
   * Clone the current annotation
   *
   * @returns {BlockAnnotation<RTETableExtensionAnnotationTypeEnum.COLOR>} A new instance of RTETableColorAnnotation with the same color key
   */
  clone() {
    return new RTETableColorAnnotation(this.colorKey);
  }
  /**
   * format table color
   *
   * @param {string} colorKey - table color
   * @returns {Nullable<VegaRTEColorSchema>} - VegaRTEColorSchema
   */
  formatColor(colorKey) {
    return RTETableColorManager.getTableColors().find((item) => item.key === colorKey);
  }
}
