import { InternalAnnotationTypeEnum } from '../../annotations/annotation.abstract';
import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Unlink the text block link group annotation strategy.
 */
export class BlockUnlinkLinkGroupStrategy extends ActionHandleStrategy {
  /**
   * Unlink the link group based on group key
   *
   * @param {UnlinkLinkGroupAction} action - The unlink link group action instance.
   * @param {RTETextBlock} target - The current text block.
   */
  handleAction(action, target) {
    const linkGroupAnnotation = target.getAnnotationByType(InternalAnnotationTypeEnum.LINK_GROUP);
    if (linkGroupAnnotation) {
      if (linkGroupAnnotation.linkGroups.size > 1) {
        linkGroupAnnotation.linkGroups.delete(action.groupKey);
      }
      else {
        target.annotationMap.delete(InternalAnnotationTypeEnum.LINK_GROUP);
      }
    }
  }
}
