import { RicosPluginToolbarButton } from "./plugin-toolbar-button.js";
class RicosPluginToolbar {
  constructor(toolbar, pluginType, services, config) {
    this.buttons = toolbar?.getButtons(config, services)?.map((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;
  }
}
export {
  RicosPluginToolbar
};
//# sourceMappingURL=plugin-toolbar.js.map
