import { SplitCellHorizontallyAction } from '../actions/split-cell-horizontally-action';
import { SplitCellVerticallyAction } from '../actions/split-cell-vertically-action';
import { SettingEventHandler, TableSettingType } from './setting-event-handler.abstract';
export var SplitCellOperationType;
(function (SplitCellOperationType) {
  SplitCellOperationType["SPLIT_CELL_HORIZONTALLY"] = "SPLIT_CELL_HORIZONTALLY";
  SplitCellOperationType["SPLIT_CELL_VERTICALLY"] = "SPLIT_CELL_VERTICALLY";
})(SplitCellOperationType || (SplitCellOperationType = {}));
/**
 * Event handler for split cell operations in a table.
 */
export class SplitCellOperationEventHandler extends SettingEventHandler {
  /**
   * @inheritDoc
   */
  canHandle(action) {
    return action[0] === TableSettingType.SPLIT_CELL;
  }
  /**
   * @inheritDoc
   */
  execute(action, extensionContext) {
    const selectedCells = extensionContext.tableSelection.getSelectedCells();
    if (selectedCells && selectedCells.length === 1) {
      const targetCell = selectedCells[0];
      const operation = action[1];
      switch (operation) {
        case SplitCellOperationType.SPLIT_CELL_HORIZONTALLY:
          this.handleSplitCellHorizontally(targetCell);
          break;
        case SplitCellOperationType.SPLIT_CELL_VERTICALLY:
          this.handleSplitCellVertically(targetCell);
          break;
        default:
          break;
      }
    }
  }
  /**
   * Splits the selected table cell horizontally (split top/bottom).
   *
   * @param {RTETableCellBlock | RTETableHeadCellBlock} selectedCell - The table cell block to split.
   */
  handleSplitCellHorizontally(selectedCell) {
    const action = new SplitCellHorizontallyAction();
    selectedCell.apply(action);
  }
  /**
   * Splits the selected table cell vertically (split left/right).
   *
   * @param {RTETableCellBlock | RTETableHeadCellBlock} selectedCell - The table cell block to split.
   */
  handleSplitCellVertically(selectedCell) {
    const action = new SplitCellVerticallyAction();
    selectedCell.apply(action);
  }
}
