var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import codeSimple from '../../../assets/code-simple';
import { RTETextNode } from '../../../dto/nodes/text-node';
import { NodeAnnotationTypeEnum } from '../../../dto/annotations/node-annotation.abstract';
import { MapToComponentField } from 'vega-slimmer/core';
import { CodeAnnotationAction } from '../../../dto/actions/code-annotation-action';
import { VisualModeToolbarButtonSlimmer } from './visual-mode-toolbar-button-slimmer.abstract';
export class CodeToolbarButtonSlimmer extends VisualModeToolbarButtonSlimmer {
  constructor() {
    super({
      icon: 'code-simple',
      tooltip: { text: 'Code' },
    });
  }
  onClick() {
    const selected = this.isSelected();
    this.selectionController
      .getSelectedNodes()
      .filter((node) => node instanceof RTETextNode)
      .forEach((node) => node.apply(new CodeAnnotationAction(!selected)));
  }
  isSelected() {
    const selectedNodes = this.selectionController.getSelectedNodes();
    return (selectedNodes.length > 0 &&
      selectedNodes
        .filter((node) => node instanceof RTETextNode)
        .map((node) => node.getAnnotationByType(NodeAnnotationTypeEnum.CODE))
        .every((annotation) => annotation && annotation.code));
  }
  isDisabled() {
    const selectedNodes = this.selectionController.getSelectedNodes();
    return (super.isDisabled() ||
      selectedNodes.some((node) => node.getAnnotationByType(NodeAnnotationTypeEnum.LINK) ||
        this.shouldDisabledToolbar(node, CodeAnnotationAction.name)));
  }
}
(() => {
  VegaInternalIconManager.register({ 'code-simple': codeSimple });
})();
__decorate([
  MapToComponentField()
], CodeToolbarButtonSlimmer.prototype, "selectionController", void 0);
