import { generateUUID } from '../../../../../utils/misc';
import { BlockToRTEBlockStrategyAbstract } from '../../../slimmers/controllers/helper/element-to-dto-strategy/block-to-rte-block-strategy.abstract';
import { RTETableBodyBlock } from '../dto/table-body-block';
import htmlElementToAnnotationGenerator from '../../../slimmers/controllers/helper/element-to-dto-strategy/annotation-handler/html-element-to-annotation-generator';
/**
 * Strategy to convert a native HTML tbody element into an RTETableBodyBlock DTO.
 */
export class TbodyToTableBodyBlockStrategy extends BlockToRTEBlockStrategyAbstract {
  /**
   * @inheritDoc
   */
  canHandle(elementsArray, currentIndex) {
    const element = elementsArray[currentIndex];
    return element && element.tagName === 'TBODY' ? 1 : 0;
  }
  /**
   * @inheritDoc
   */
  handle(elementsArray, options) {
    return RTETableBodyBlock.from({
      id: generateUUID(),
      type: 'table-body',
      annotations: htmlElementToAnnotationGenerator.generate(RTETableBodyBlock, elementsArray[0], options),
      children: [],
    }, options);
  }
  /**
   * @inheritDoc
   */
  appendChildBlocks(currentBlock, childBlocks) {
    currentBlock.children = childBlocks.map((block) => {
      block.parent = currentBlock;
      return block;
    });
  }
  /**
   * @inheritDoc
   */
  shouldProceedToElementChildren() {
    return true;
  }
}
