import { RTEBlock } from '../../../dto/blocks/block.abstract';
/**
 * Class representing a table row block in the rich text editor.
 */
export class RTETableRowBlock extends RTEBlock {
  constructor(id) {
    super(id);
    this.type = 'table-row';
    this.children = [];
  }
  /**
   * @inheritDoc
   */
  static from(block, options) {
    const rowBlock = new RTETableRowBlock(block.id);
    super.convertAnnotationsToMap(rowBlock.annotationMap, Object.assign({}, block.annotations));
    rowBlock.children = super.generateBlockChildren(block.children, options, rowBlock);
    return rowBlock;
  }
  /**
   * @inheritDoc
   */
  clone(parent) {
    const clonedBlock = new RTETableRowBlock(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) => {
      return child.toHtml(options);
    })
      .join('');
    const attrStr = super.generateAttributeString(options);
    return `<tr${attrStr}>${childrenHtml}</tr>`;
  }
  /**
   * @inheritDoc
   */
  toJSON() {
    return Object.assign(Object.assign({}, super.toJSON()), { type: this.type, children: this.children.map((child) => child.toJSON()) });
  }
}
