import { RTETableExtensionAnnotationTypeEnum, } from '../annotations/table-annotation';
import { UpdateCursorPositionAction } from '../../../dto/actions/update-cursor-position-action';
/**
 * Event handler for row operations in a table.
 */
export class TablePropertiesEventHandler {
  /**
   * Generate form object from table block
   *
   * @param {RTETableBlock} tableBlock - The table block
   * @returns {RTETablePropertiesType} The generated form object
   */
  static generateTablePropertiesForm(tableBlock) {
    const annotation = tableBlock.annotationMap.get(RTETableExtensionAnnotationTypeEnum.TABLE);
    let result = {
      borderStyle: 'none',
      borderColor: '',
      borderWidth: '',
      backgroundColor: '',
      width: '',
      height: '',
      textAlign: 'center',
    };
    if (annotation) {
      const annotationJSON = annotation.toJSON().table;
      const { style = 'none', color = '', width = '', } = annotationJSON.border || { style: 'none', color: '', width: '' };
      result = {
        backgroundColor: annotationJSON.backgroundColor || '',
        width: annotationJSON.width || '',
        height: annotationJSON.height || '',
        textAlign: annotationJSON.alignment,
        borderStyle: style,
        borderColor: color,
        borderWidth: width,
      };
    }
    return result;
  }
  /**
   * Update the rich text editor cursor position
   *
   * @param {RTETableExtensionContext} extensionContext - The table extension context.
   * @param {Nullable<RTENode>} focusNode - The node to focus on.
   */
  updateCursorPosition(extensionContext, focusNode) {
    if (extensionContext && focusNode) {
      extensionContext.host.value.apply(new UpdateCursorPositionAction(focusNode, 0));
    }
  }
}
