import { CommonAnnotation, CommonAnnotationTypeEnum } from './common-annotation.abstract';
/**
 * Annotation to add custom attributes of element
 */
export class CustomStyleAnnotation extends CommonAnnotation {
  constructor(customStyle) {
    super();
    this.type = CommonAnnotationTypeEnum.CUSTOM_STYLE;
    this.customStyle = customStyle;
  }
  /**
   * Generate the map item for the annotation
   *
   * @param {AnnotationStyle} customStyle - custom attribute annotation
   * @returns {[CommonAnnotationTypeEnum.CUSTOM_STYLE, CustomStyleAnnotation]} Map item for the annotation
   */
  static from(customStyle) {
    return [CommonAnnotationTypeEnum.CUSTOM_STYLE, new CustomStyleAnnotation(customStyle)];
  }
  /**
   * Generate the JSON representation of the annotation
   *
   * @returns {Record<string, unknown>} JSON representation of the annotation
   */
  toJSON() {
    return {
      customStyle: this.customStyle,
    };
  }
  /**
   * Create a new custom attribute annotation
   *
   * @returns {CustomStyleAnnotation} - Custom attribute annotation
   */
  clone() {
    return new CustomStyleAnnotation(this.customStyle);
  }
  /**
   * Generate the custom attribute for the annotation
   *
   * @returns {AnnotationStyle} custom attribute
   */
  renderStyle() {
    return this.customStyle;
  }
  /**
   * Remove the style
   *
   * @param {string[]} styleKeys - custom attribute annotation
   * @returns {AnnotationStyle} Map item for the annotation
   */
  removeStyles(styleKeys) {
    const customStyle = Object.assign({}, this.customStyle);
    styleKeys.forEach((item) => delete customStyle[item]);
    return customStyle;
  }
  /**
   * Generate the custom style string for the annotation
   *
   * @returns {string} custom style string
   */
  toString() {
    return `style="${Object.entries(this.customStyle)
      .map(([key, value]) => `${key}: ${value};`)
      .join(' ')}"`;
  }
}
