import { generateUUID } from '../../../../../utils/misc';
import { ElementToDTOStrategy } from '../../../slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy.abstract';
import { RTEFunctionBlock } from '../dto/function-block';
/**
 * Strategy to convert a div with class 'statement' into an function block.
 */
export class DivToFunctionBlockStrategy extends ElementToDTOStrategy {
  /**
   * @inheritDoc
   */
  canHandle(elementsArray, currentIndex) {
    const element = elementsArray[currentIndex];
    return element &&
      element.tagName === 'DIV' &&
      element.classList.contains('statement') &&
      element.childNodes.length &&
      element.querySelector('.statementsyntax')
      ? 1
      : 0;
  }
  /**
   * @inheritDoc
   */
  handle() {
    return RTEFunctionBlock.from({
      id: generateUUID(),
      type: 'function-block',
      annotations: {
        customClass: ['statement'],
      },
      children: [],
    });
  }
  /**
   * @inheritDoc
   */
  appendChildBlocks(currentBlock, childBlocks) {
    currentBlock.children = childBlocks.map((block) => {
      block.parent = currentBlock;
      return block;
    });
  }
  /**
   * @inheritDoc
   */
  shouldProceedToElementChildren() {
    return true;
  }
}
