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 italic from '../../../assets/italic';
import { MapToComponentField } from 'vega-slimmer/core';
import { ItalicAnnotationAction } from '../../../dto/actions/italic-annotation-action';
import { NodeAnnotationTypeEnum } from '../../../dto/annotations/node-annotation.abstract';
import { RTETextNode } from '../../../dto/nodes/text-node';
import { VisualModeToolbarButtonSlimmer } from './visual-mode-toolbar-button-slimmer.abstract';
export class ItalicToolbarButtonSlimmer extends VisualModeToolbarButtonSlimmer {
  constructor() {
    super({
      icon: 'italic',
      tooltip: { text: 'Italic' },
    });
  }
  isSelected() {
    const selectedNodes = this.selectionController
      .getSelectedNodes()
      .filter((node) => node instanceof RTETextNode);
    return (selectedNodes.length > 0 &&
      selectedNodes.every((node) => { var _a; return (_a = node.getAnnotationByType(NodeAnnotationTypeEnum.ITALIC)) === null || _a === void 0 ? void 0 : _a.italic; }));
  }
  onClick() {
    const italic = this.isSelected();
    this.selectionController
      .getSelectedNodes()
      .filter((node) => node instanceof RTETextNode)
      .forEach((node) => node.apply(new ItalicAnnotationAction(!italic)));
  }
  isDisabled() {
    const selectedNodes = this.selectionController.getSelectedNodes();
    return (super.isDisabled() ||
      selectedNodes.some((node) => {
        var _a;
        return ((_a = node.getAnnotationByType(NodeAnnotationTypeEnum.CODE)) === null || _a === void 0 ? void 0 : _a.code) ||
          this.shouldDisabledToolbar(node, ItalicAnnotationAction.name);
      }));
  }
}
(() => {
  VegaInternalIconManager.register({ italic });
})();
__decorate([
  MapToComponentField()
], ItalicToolbarButtonSlimmer.prototype, "selectionController", void 0);
