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