import { ModifyContentActionType } from '../actions/modify-content-action.abstract';
import { NodeTypeEnum } from './node.abstract';
import { ActionHandleStrategyRegistry } from '../action-handle-strategies/action-handle-strategy-registry';
import { UpdateCodeBlockStrategy } from '../action-handle-strategies/modify-content-strategies/update-code-block-strategy';
import { SelectionChangeAction } from '../actions/selection-change-action';
import { CodeNodeSetSelectionRangeAnnotationStrategy } from '../action-handle-strategies/apply-annotation-strategies/code-node-set-selection-range-strategy';
import { RTEDecoratorNode } from './decorator-node';
import { CustomStyleAnnotation } from '../annotations/custom-style-annotation';
import { CodeBlockNodeFilterStylesStrategy } from '../filter-styles-strategies/code-block/code-node-filter-styles-strategy';
import { CommonAnnotationTypeEnum } from '../annotations/common-annotation.abstract';
/**
 * RTE code node DTO class.
 */
export class RTECodeBlockNode extends RTEDecoratorNode {
  constructor(id, content, language, parentBlock) {
    super(id);
    this.type = NodeTypeEnum.CODE_BLOCK_NODE;
    this.text = '';
    this.annotationMap = new Map();
    this.text = content;
    this.parent = parentBlock;
    this.language = language;
    this.annotationMap.set(CommonAnnotationTypeEnum.CUSTOM_STYLE, new CustomStyleAnnotation(CodeBlockNodeFilterStylesStrategy.STYLES));
  }
  /**
   * The code node toJSON method will called internal.
   *
   * @returns {VegaRTECodeNode} - An object contains content property.
   */
  toJSON() {
    return { id: this.id, type: 'text', text: this.text, language: this.language };
  }
  /**
   * @inheritDoc
   */
  toHtml(options) {
    const attrs = this.generateAttributeString(options);
    return `<code${attrs}>${this.text}</code>`;
  }
  /**
   * @inheritDoc
   */
  clone(parent) {
    const cloned = new RTECodeBlockNode(this.id, this.text, this.language, parent);
    return cloned;
  }
  /**
   * @inheritDoc
   */
  doAnnotationActionApply(action) {
    ActionHandleStrategyRegistry.executeTheStrategy(action, this);
  }
  /**
   * @inheritDoc
   */
  doModifyActionApply(action) {
    ActionHandleStrategyRegistry.executeTheStrategy(action, this);
  }
}
(() => {
  ActionHandleStrategyRegistry.register(ModifyContentActionType.UPDATE_CODE_BLOCK, RTECodeBlockNode.name, new UpdateCodeBlockStrategy());
  ActionHandleStrategyRegistry.register(SelectionChangeAction.name, RTECodeBlockNode.name, new CodeNodeSetSelectionRangeAnnotationStrategy());
})();
