import { RTEBlock } from '../../../dto/blocks/block.abstract';
import { RTELogicControlNode } from '../dto/logic-control-node';
/**
 * Class representing a logic control block in the rich text editor.
 */
export class RTELogicControlBlock extends RTEBlock {
  constructor(id, statementText, parent) {
    super(id);
    this.type = 'logic-control-block';
    this.children = [];
    this.statementText = '';
    this.statementText = statementText;
    this.children = [new RTELogicControlNode(`${id}-node-1`, statementText, this)];
    if (parent) {
      this.parent = parent;
    }
  }
  /**
   * Create a logic control block from a JSON representation.
   *
   * @param {VegaRTELogicControlBlock} json - The JSON object representing the logic control block.
   * @returns {RTELogicControlBlock} - The created logic control block.
   */
  static from(json) {
    const block = new RTELogicControlBlock(json.id, json.statementText);
    return block;
  }
  /**
   * Check the block is not empty.
   *
   * @returns {boolean} - Always true for logic control block.
   */
  isNotEmpty() {
    return true;
  }
  /**
   * Get the last node of the block.
   *
   * @returns {RTELogicControlNode} - The last node in the block.
   */
  getLastNode() {
    return this.children[this.children.length - 1];
  }
  /**
   * Convert the block to its HTML representation.
   *
   * @returns {string} - The HTML string of the logic control block.
   */
  toHtml() {
    return `<div class='statementsyntax' contenteditable='false'>${this.statementText}</div>`;
  }
  /**
   * Clone the current block instance.
   *
   * @param { RTEFunctionBlock } parent - The parent function block for the cloned instance.
   * @returns {RTELogicControlBlock} - A new instance of RTEStatementSyntaxBlock.
   */
  clone(parent) {
    return new RTELogicControlBlock(this.id, this.statementText, parent);
  }
  /**
   * Get the JSON representation of the block.
   *
   * @returns {VegaRTELogicControlBlock} - The JSON object of the logic control block.
   */
  toJSON() {
    return {
      id: this.id,
      type: this.type,
      statementText: this.statementText,
    };
  }
}
