import { RTETextNode } from '../../dto/nodes/text-node';
/**
 * Token node for the Vega Rich Text Editor.
 */
export class RTETokenNode extends RTETextNode {
  constructor(id, token, text, parentBlock, annotations) {
    super(id, text, parentBlock, annotations);
    this.dtoName = RTETokenNode.dtoName;
    this.type = 'token';
    this.token = token;
    this.text = text;
  }
  /**
   * @inheritDoc
   */
  static from(value, parent) {
    const node = new RTETokenNode(value.id, value.token, value.text, parent);
    if (value.annotations) {
      node.annotationMap = this.generateTextAnnotationMap(value.annotations);
    }
    return node;
  }
  /**
   * Converts the token node to a JSON representation.
   *
   * @returns {VegaRTETokenNode} - The JSON representation of the token node.
   */
  toJSON() {
    const json = super.toJSON();
    return Object.assign({ id: this.id, type: this.type, text: this.text, token: this.token }, (json.annotations ? { annotations: json.annotations } : {}));
  }
  /**
   * Determines if the token node is content editable.
   *
   * @returns {boolean} - Always returns false for token nodes.
   */
  isContentEditable() {
    return false;
  }
  /**
   * Clones the token node.
   *
   * @param {RTETextBlock} parent - The parent block for the cloned node.
   * @returns {RTETokenNode} - The cloned token node.
   */
  clone(parent) {
    return new RTETokenNode(this.id, this.token, this.text, parent, this.annotationMap);
  }
  /**
   * Converts the token node to an HTML representation.
   *
   * @returns {string} - The HTML representation of the token node.
   */
  toHtml() {
    return `<span class="token" contenteditable="false" template-token-key="${this.token}" token-key="${this.token}"${super.generateAttributeString()}>${this.text}</span>`;
  }
}
RTETokenNode.dtoName = 'RTETokenNode';
