"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plugin_toolbar_exports = {};
__export(plugin_toolbar_exports, {
  RicosPluginToolbar: () => RicosPluginToolbar
});
module.exports = __toCommonJS(plugin_toolbar_exports);
var import_plugin_toolbar_button = require("./plugin-toolbar-button.js");
class RicosPluginToolbar {
  constructor(toolbar, pluginType, services, config) {
    this.buttons = toolbar?.getButtons(config, services)?.map((button) => import_plugin_toolbar_button.RicosPluginToolbarButton.of(button, services)) || [];
    this.pluginType = pluginType;
    this.customIsVisible = toolbar.isVisible;
    this.customResolveReferenceElement = toolbar.resolveReferenceElement;
  }
  static of(toolbar, pluginType, services, config) {
    return new RicosPluginToolbar(toolbar, pluginType, services, config);
  }
  getButtons() {
    return this.buttons;
  }
  toToolbarItemsConfig() {
    return this.buttons.map((button) => button.toToolbarItemConfig());
  }
  getToolbarButtonsRenderers() {
    return this.buttons.reduce((renderers, button) => {
      return {
        ...renderers,
        ...button.getRenderer()
      };
    }, {});
  }
  isVisible(selection, editor) {
    if (!this.buttons.length) {
      return false;
    }
    const isVisibleInSelection = "node" in selection && selection.node?.type.name === this.pluginType;
    return this.customIsVisible ? isVisibleInSelection || this.customIsVisible(selection, editor) : isVisibleInSelection;
  }
  getReferenceElementResolver() {
    return this.customResolveReferenceElement;
  }
}
//# sourceMappingURL=plugin-toolbar.js.map
