import { ActionHandleStrategy } from '../../../dto/action-handle-strategies/action-handle-strategy.abstract';
import { InsertChildrenBeforeAction } from '../../../dto/actions/insert-children-before-block';
import { RemoveChildrenAction } from '../../../dto/actions/remove-child-action';
import { RTETableCellBlock } from '../dto/table-cell-block';
import { RTETableHeadCellBlock } from '../dto/table-head-cell-block';
/**
 * Strategy to replace a fully overlapped table cell.
 */
export class ReplaceTableCellStrategy extends ActionHandleStrategy {
  /**
   * @inheritDoc
   */
  handleAction(action, row) {
    const { cell, targetCellType } = action.payload;
    const newCell = targetCellType === 'table-head-cell'
      ? RTETableHeadCellBlock.from(cell.toJSON())
      : RTETableCellBlock.from(cell.toJSON());
    row.apply(new InsertChildrenBeforeAction(cell, newCell));
    row.apply(new RemoveChildrenAction(cell));
  }
}
