import { BoldAnnotationAction } from '../../actions/bold-annotation-action';
import { DeleteNodeAnnotationAction } from '../../actions/delete-node-annotation-action';
import { NodeAnnotationTypeEnum } from '../../annotations/node-annotation.abstract';
import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Update the text block text style strategy.
 */
export class BlockUpdateTextStyleStrategy extends ActionHandleStrategy {
  /**
   * Update the text block type and add or remove the bold style from child nodes.
   *
   * @param {TextStyleAnnotationAction} action - The text style annotation action.
   * @param {RTETextBlock} target - The current text block.
   */
  handleAction(action, target) {
    if (target.type !== 'list-item') {
      target.type = action.textStyle;
    }
    if (action.bold) {
      target.children.forEach((node) => {
        const boldAnnotationAction = new BoldAnnotationAction(true);
        boldAnnotationAction.doSplit = false;
        node.apply(boldAnnotationAction);
      });
    }
    else {
      target.children.forEach((node) => {
        node.apply(new DeleteNodeAnnotationAction(NodeAnnotationTypeEnum.BOLD));
      });
    }
    this.updateCustomStyleAnnotation(target, ['fontFamily', 'lineHeight', 'fontWeight', 'fontSize']);
  }
}
