import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
/** Handle custom class annotation */
export class CustomClassAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * Can be handle.
   *
   * @param {RTEDtoClassPrototype} targetDto - Target DTO.
   * @param {HtmlElementToAnnotationGenerateOptions} [options] - Options for annotation generator.
   * @returns {boolean} - .
   */
  canHandle(targetDto, options) {
    return !options.skipCustomAnnotations && !!targetDto;
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @returns {VegaRTETextAnnotations} - Annotation.
   */
  handle(element) {
    const classes = this.getCustomClass(element);
    return classes.length > 0 ? { customClass: classes } : {};
  }
  /**
   * Get the custom class
   *
   * @param {HTMLElement} element - current element.
   * @returns {string[]} - the class after .
   */
  getCustomClass(element) {
    return element.classList
      .toString()
      .split(' ')
      .filter((item) => !item.includes('v-rte') && item !== '');
  }
}
