import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
import { STRIKETHROUGH_TEXT_DECORATION } from '../../../../../dto/annotations/text-format-default-styles';
/** Handle strike through annotation */
export class StrikeThroughAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * @inheritDoc
   */
  canHandle(targetDto) {
    return targetDto.dtoName === 'RTETextNode';
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @param {VegaRTETextAnnotations} parentAnnotations - Parent annotations.
   * @returns {VegaRTETextAnnotations} - Annotation.
   */
  handle(element, parentAnnotations = {}) {
    return this.isStrikethrough(element) || parentAnnotations.strikethrough
      ? { strikethrough: true }
      : {};
  }
  /**
   * Is strikethrough element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {boolean} - boolean.
   */
  isStrikethrough(element) {
    return (element.style.textDecoration.includes(STRIKETHROUGH_TEXT_DECORATION) ||
      element.nodeName === 'S' ||
      element.nodeName === 'DEL' ||
      element.classList.contains('v-rte--strikethrough'));
  }
}
