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