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