import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
import { UNDERLINE_TEXT_DECORATION } from '../../../../../dto/annotations/text-format-default-styles';
/** Handle underline annotation */
export class UnderlineAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * @inheritDoc
   */
  canHandle(targetDto) {
    return targetDto.name === 'RTETextNode';
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @param {VegaRTETextAnnotations} parentAnnotations - Parent annotations.
   * @returns {VegaRTETextAnnotations} - Annotation.
   */
  handle(element, parentAnnotations = {}) {
    return this.isUnderline(element) || parentAnnotations.underline ? { underline: true } : {};
  }
  /**
   * Is underline element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {boolean} - boolean.
   */
  isUnderline(element) {
    return (element.style.textDecoration.includes(UNDERLINE_TEXT_DECORATION) ||
      element.nodeName === 'U' ||
      element.nodeName === 'INS' ||
      element.classList.contains('v-rte--underline'));
  }
}
