import { VegaRTEContent } from '../../../dto/content-state';
import { UpdateCursorPositionAction } from '../../../dto/actions/update-cursor-position-action';
export var TableSettingType;
(function (TableSettingType) {
  TableSettingType["ROW"] = "ROW";
  TableSettingType["CAPTION"] = "CAPTION";
  TableSettingType["COLUMN"] = "COLUMN";
  TableSettingType["MERGE_CELLS"] = "MERGE_CELLS";
  TableSettingType["TABLE"] = "TABLE";
  TableSettingType["CELL"] = "CELL";
  TableSettingType["SPLIT_CELL"] = "SPLIT_CELL";
})(TableSettingType || (TableSettingType = {}));
/**
 * Abstract class for setting event handlers.
 */
export class SettingEventHandler {
  /**
   * Applies a cursor update action so the editor focuses on the resolved node.
   *
   * @param {RTETableBlock} block - Table block currently being toggled.
   * @param {Nullable<RTENode>} focusNode - Target node that should receive the caret.
   */
  syncCursorPosition(block, focusNode) {
    const rootContent = this.findRootContent(block);
    if (focusNode && rootContent) {
      const offset = focusNode.getRangeEndOffset();
      rootContent.apply(new UpdateCursorPositionAction(focusNode, offset));
    }
  }
  /**
   * Walks up the parent chain to locate the nearest VegaRTEContent root.
   *
   * @param {RTETableBlock} block - Table block used as the starting point.
   * @returns {Nullable<VegaRTEContent>} Content root containing the table, if found.
   */
  findRootContent(block) {
    let currentParent = block.parent;
    while (currentParent) {
      if (currentParent instanceof VegaRTEContent) {
        return currentParent;
      }
      currentParent = currentParent.parent;
    }
  }
}
