import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
/** Handle text align annotation */
export class TextAlignAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * Can be handle.
   *
   * @param {RTEDtoClassPrototype} targetDto - Target DTO.
   * @returns {boolean} - .
   */
  canHandle(targetDto) {
    return ['RTETextBlock', 'RTEListItemBlock', 'RTEListBlock'].includes(targetDto.dtoName);
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @returns {VegaRTEBlockAnnotations} - Annotation.
   */
  handle(element) {
    const textAlign = this.getTextAlign(element);
    return textAlign ? { textAlign: textAlign } : {};
  }
  /**
   * Get text align of current element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {Nullable<VegaRTEBlockAlignment>} - Text align.
   */
  getTextAlign(element) {
    const classList = element.classList;
    if (classList.contains(`v-rte--horizontal-alignment-left`)) {
      return 'left';
    }
    else if (classList.contains(`v-rte--horizontal-alignment-center`)) {
      return 'center';
    }
    else if (classList.contains(`v-rte--horizontal-alignment-right`)) {
      return 'right';
    }
    else if (classList.contains(`v-rte--horizontal-alignment-justify`)) {
      return 'justify';
    }
    const style = element.style;
    switch (style.textAlign) {
      case 'center':
        return 'center';
      case 'right':
        return 'right';
      case 'justify':
        return 'justify';
      case 'left':
        return 'left';
      default:
        return null;
    }
  }
}
