import { RTEBlock } from '../../../dto/blocks/block.abstract';
/**
 * Class representing a table body block in the rich text editor.
 */
export class RTETableBodyBlock extends RTEBlock {
  constructor(id) {
    super(id);
    this.type = 'table-body';
    this.children = [];
  }
  /**
   * @inheritDoc
   */
  static from(block, options) {
    const tableBodyBlock = new RTETableBodyBlock(block.id);
    super.convertAnnotationsToMap(tableBodyBlock.annotationMap, Object.assign({}, block.annotations));
    tableBodyBlock.children = super.generateBlockChildren(block.children, options, tableBodyBlock);
    return tableBodyBlock;
  }
  /**
   * @inheritDoc
   */
  clone(parent) {
    const clonedBlock = new RTETableBodyBlock(this.id);
    clonedBlock.children = this.children.map((child) => child.clone(clonedBlock));
    clonedBlock.parent = parent;
    clonedBlock.annotationMap = super.cloneAnnotations();
    return clonedBlock;
  }
  /**
   * @inheritDoc
   */
  getLastNode() {
    return this.children[this.children.length - 1].getLastNode();
  }
  /**
   * @inheritDoc
   */
  isNotEmpty() {
    return this.children.length > 0;
  }
  /**
   * @inheritDoc
   */
  toHtml(options) {
    const childrenHtml = this.children.map((child) => child.toHtml(options)).join('');
    const attrStr = super.generateAttributeString(options);
    return `<tbody${attrStr}>${childrenHtml}</tbody>`;
  }
  /**
   * @inheritDoc
   */
  toJSON() {
    return Object.assign(Object.assign({}, super.toJSON()), { type: this.type, children: this.children.map((child) => child.toJSON()) });
  }
}
