import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
import { ITALIC_FONT_STYLE } from '../../../../../dto/annotations/text-format-default-styles';
/** Handle italic annotation */
export class ItalicAnnotationHandler 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.isItalic(element) || parentAnnotations.italic ? { italic: true } : {};
  }
  /**
   * Is italic element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {boolean} - boolean.
   */
  isItalic(element) {
    return (element.nodeName === 'I' ||
      element.style.fontStyle === ITALIC_FONT_STYLE ||
      element.nodeName === 'EM' ||
      element.classList.contains('v-rte--italic'));
  }
}
