import { AnnotationGeneratorStrategyAbstract } from './annotation-generator-strategy.abstract';
/** Handle indent annotation */
export class IndentAnnotationHandler extends AnnotationGeneratorStrategyAbstract {
  /**
   * @inheritDoc
   */
  canHandle(targetDto) {
    return ['RTETextBlock', 'RTEListItemBlock', 'RTEListBlock'].includes(targetDto.dtoName);
  }
  /**
   * Handle annotation.
   *
   * @param {HTMLElement} element - Current elements.
   * @returns {VegaRTEBlockAnnotations} - Annotation.
   */
  handle(element) {
    const indent = this.getIndent(element);
    return indent ? { indent: indent } : {};
  }
  /**
   * Get indent of current element.
   *
   * @param {HTMLElement} element - current element.
   * @returns {Nullable<number>} - Indent.
   */
  getIndent(element) {
    const style = element.style;
    let marginLeft;
    if (style.marginLeft) {
      marginLeft = style.marginLeft;
    }
    else if (style.margin) {
      const margins = style.margin.split(' ');
      switch (margins.length) {
        case 4:
          marginLeft = margins[3];
          break;
        case 2:
        case 3:
          marginLeft = margins[1];
          break;
        default:
          marginLeft = margins[0];
          break;
      }
    }
    else {
      return null;
    }
    const marginLeftNumber = Number(marginLeft.replace('px', ''));
    return marginLeftNumber && marginLeftNumber >= 0 ? Math.floor(marginLeftNumber / 16) : null;
  }
}
