import { ActionHandleStrategy } from '../../../dto/action-handle-strategies/action-handle-strategy.abstract';
import { getActualColumnPosition } from '../utils/utils';
/**
 * Abstract base strategy for handling table column operations.
 * Provides common functionality for all column-related strategies.
 */
export class TableColumnStrategy extends ActionHandleStrategy {
  /**
   * Finds the index range of cells within a table row.
   * Returns the start and end indices of the given cell range.
   *
   * @param {(RTETableCellBlock | RTETableHeadCellBlock)[]} cellRange - The range of table cells to find indices for.
   * @param {RTETableRowBlock[]} allTableRows - All table rows.
   * @param {string[][]} grid - The 2D grid representation of the table
   * @returns {[number, number]} A tuple containing the start and end indices.
   */
  getBoundaryCellColumnRange(cellRange, allTableRows, grid) {
    let minCol = Number.POSITIVE_INFINITY;
    let maxCol = Number.NEGATIVE_INFINITY;
    cellRange.forEach((cell) => {
      const logicalCol = getActualColumnPosition(cell, allTableRows, grid);
      minCol = Math.min(minCol, logicalCol);
      maxCol = Math.max(maxCol, logicalCol);
    });
    return [minCol, maxCol];
  }
}
