var __rest = (this && this.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
import { RTEBlock } from '../../../dto/blocks/block.abstract';
import { ActionHandleStrategyRegistry } from '../../../dto/action-handle-strategies/action-handle-strategy-registry';
import { ModifyContentActionType } from '../../../dto/actions/modify-content-action.abstract';
import { InsertChildrenBeforeStrategy } from '../../../dto/action-handle-strategies/modify-content-strategies/insert-children-before-strategy';
import { PasteContentStrategy } from '../../../dto/action-handle-strategies/modify-content-strategies/paste-content-strategy';
import { RTETableExtensionAnnotationTypeEnum } from '../annotations/table-annotation';
import { RTETableCaptionAnnotation } from '../annotations/table-caption-annotation';
/**
 * Represents the optional caption block for a table.
 */
export class RTETableCaptionBlock extends RTEBlock {
  constructor(id, options) {
    super(id);
    this.dtoName = RTETableCaptionBlock.dtoName;
    this.type = 'table-caption';
    const { autoMatchFormat } = options || { autoMatchFormat: true };
    if (autoMatchFormat) {
      this.annotationMap.set(RTETableExtensionAnnotationTypeEnum.CAPTION, new RTETableCaptionAnnotation());
    }
  }
  /**
   * @inheritDoc
   */
  static from(block, options) {
    const captionBlock = new RTETableCaptionBlock(block.id, options);
    const _a = block.annotations || {}, { caption } = _a, restAnnotations = __rest(_a, ["caption"]);
    if (caption) {
      captionBlock.annotationMap.set(RTETableExtensionAnnotationTypeEnum.CAPTION, new RTETableCaptionAnnotation());
    }
    super.convertAnnotationsToMap(captionBlock.annotationMap, Object.assign({}, restAnnotations));
    captionBlock.children = super.generateBlockChildren(block.children, options, captionBlock);
    return captionBlock;
  }
  /**
   * @inheritDoc
   */
  clone(parent) {
    const clonedBlock = new RTETableCaptionBlock(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 && this.children.some((child) => child.isNotEmpty());
  }
  /**
   * @inheritDoc
   */
  toHtml(options) {
    const childrenHtml = this.children
      .map((child) => child.toHtml(options))
      .join('');
    const attrStr = super.generateAttributeString(options);
    return `<caption${attrStr}>${childrenHtml}</caption>`;
  }
  /**
   * @inheritDoc
   */
  toJSON() {
    return Object.assign(Object.assign({}, super.toJSON()), { type: this.type, children: this.children.map((child) => child.toJSON()) });
  }
}
(() => {
  ActionHandleStrategyRegistry.register(ModifyContentActionType.INSERT_CHILDREN_BEFORE, RTETableCaptionBlock.name, new InsertChildrenBeforeStrategy());
  ActionHandleStrategyRegistry.register(ModifyContentActionType.PASTE_CONTENT, RTETableCaptionBlock.name, new PasteContentStrategy());
})();
RTETableCaptionBlock.dtoName = 'RTETableCaptionBlock';
