import { RTETableExtensionAnnotationTypeEnum } from '../annotations/table-annotation';
import { RTETableCellBlock } from './table-cell-block';
import { RTETableHeadCellAnnotation } from '../annotations/table-head-cell-annotation';
/**
 * Class representing a table head block in the rich text editor.
 */
export class RTETableHeadCellBlock extends RTETableCellBlock {
  constructor(id, options) {
    super(id, options);
    this.dtoName = RTETableHeadCellBlock.dtoName;
    this.type = 'table-head-cell';
    const { autoMatchFormat } = options || { autoMatchFormat: true };
    if (autoMatchFormat) {
      this.annotationMap.set(RTETableExtensionAnnotationTypeEnum.CELL, new RTETableHeadCellAnnotation());
    }
  }
  /**
   * @inheritDoc
   */
  static from(block, options) {
    var _a;
    const headCellBlock = new RTETableHeadCellBlock(block.id, options);
    super.convertAnnotationsToMap(headCellBlock.annotationMap, Object.assign({}, block.annotations));
    if ((_a = block.annotations) === null || _a === void 0 ? void 0 : _a.tableCell) {
      headCellBlock.annotationMap.set(...RTETableHeadCellAnnotation.from(block.annotations.tableCell, options === null || options === void 0 ? void 0 : options.autoMatchFormat));
    }
    headCellBlock.children = super.generateBlockChildren(block.children, options, headCellBlock);
    return headCellBlock;
  }
  /**
   * @inheritDoc
   */
  clone(parent) {
    const clonedBlock = new RTETableHeadCellBlock(this.id);
    clonedBlock.children = this.children.map((child) => child.clone(clonedBlock));
    clonedBlock.parent = parent;
    clonedBlock.annotationMap = super.cloneAnnotations();
    return clonedBlock;
  }
  /**
   * @inheritDoc
   */
  toHtml(options) {
    const childrenHtml = this.children.map((child) => child.toHtml(options)).join('');
    const attrStr = super.generateAttributeString(options);
    return `<th${attrStr}>${childrenHtml}</th>`;
  }
  /**
   * @inheritDoc
   */
  toJSON() {
    return Object.assign(Object.assign({}, super.toJSON()), { type: this.type, children: this.children.map((child) => child.toJSON()) });
  }
}
RTETableHeadCellBlock.dtoName = 'RTETableHeadCellBlock';
