import { generateUUID } from '../../../../../../utils/misc';
import { RTETextBlock } from '../../../../dto/blocks/text-block';
import htmlElementToAnnotationGenerator from './annotation-handler/html-element-to-annotation-generator';
import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
/** Transform inline block element to text block DTO */
export class InlineBlockToRTETextBlockStrategy extends BlockToRTEBlockStrategyAbstract {
  /**
   * Can be handle.
   *
   * @param {HTMLElement[]} elementsArray - Current elements.
   * @param {number} currentIndex - Current element index.
   * @returns {number} - can be handled element count.
   */
  canHandle(elementsArray, currentIndex) {
    return [
      'heading-1',
      'heading-2',
      'heading-3',
      'heading-4',
      'heading-5',
      'heading-6',
      'title',
      'subtitle',
    ].includes(super.matchTextBlockType(elementsArray[currentIndex]))
      ? 1
      : 0;
  }
  /**
   * Parse to a text block.
   *
   * @param {HTMLElement[]} elementsArray - Current elements.
   * @param {VegaRTETransformOptions} [options] - Options for transformation.
   * @returns {Nullable<RTEContentBlock>} - Text block.
   */
  handle(elementsArray, options) {
    const nodes = this.generateChildNodes(Array.from(elementsArray[0].childNodes), {}, options);
    if (nodes.length === 0)
      return null;
    return RTETextBlock.from({
      id: generateUUID(),
      type: super.matchTextBlockType(elementsArray[0]),
      nodes: nodes,
      annotations: htmlElementToAnnotationGenerator.generate(RTETextBlock, elementsArray[0], options),
    }, options);
  }
  /* istanbul ignore next */
  /**
   * Append child blocks.
   */
  // eslint-disable-next-line @typescript-eslint/no-empty-function
  appendChildBlocks() { }
  /**
   * Should continue process to child elements.
   *
   * @returns {boolean} - boolean.
   */
  shouldProceedToElementChildren() {
    return false;
  }
}
