import { ActionHandlerInterceptor } from '../../../dto/action-handle-strategies/action-handle-interceptor.abstract';
import { methodPlaceholder } from 'vega-slimmer/core';
import { RTETableCellBlock } from '../dto/table-cell-block';
/**
 * Interceptor to prevent deletion of a table cell if it is the cell with empty content.
 */
export class PreventCellContentDeleteInterceptor extends ActionHandlerInterceptor {
  /**
   * Prevent deletion if the target block is the only child of a table cell and is empty.
   *
   * @param {DeleteBlockContentAction} action - the action to be intercepted
   * @param {RTETextBlock} target - the target block
   * @returns {boolean} - true if the deletion should be intercepted, false otherwise
   */
  canIntercept(action, target) {
    const cell = target.parent;
    const isSingleCellChild = cell instanceof RTETableCellBlock && cell.children.length === 1;
    return isSingleCellChild && action.startOffset === 0;
  }
  /**
   * @inheritDoc
   */
  intercept() {
    methodPlaceholder();
  }
}
