import { generateUUID } from '../../../../../../utils/misc';
import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
import { RTECodeBlock } from '../../../../dto/blocks/code-block';
/** Transform other editor code element which has attribute data-language to RTE code block DTO */
export class JiraCodeToRTECodeBlockStrategy 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 (elementsArray[currentIndex].tagName === 'PRE' ||
      elementsArray[currentIndex].tagName === 'CODE') &&
      elementsArray[currentIndex].hasAttribute('data-language')
      ? 1
      : 0;
  }
  /**
   * Parse to a code block.
   *
   * @param {HTMLElement[]} elementsArray - Current elements.
   * @returns {Nullable<RTECodeBlock>} - Code block.
   */
  handle(elementsArray) {
    const codeRef = elementsArray[0];
    if (codeRef) {
      const content = codeRef.textContent;
      const language = codeRef.dataset
        .language;
      return RTECodeBlock.from({
        id: generateUUID(),
        type: 'code-block',
        content,
        language,
      });
    }
  }
  /* 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;
  }
}
