import { RicosPluginToolbar } from "./plugin-toolbar.js";
class EditorPlugin {
  static of(plugin, services) {
    return new EditorPlugin(plugin, services);
  }
  constructor(plugin, services) {
    this.plugin = plugin;
    this.services = services;
  }
  initAddButtons() {
    if (this.plugin.getAddButtons) {
      this.addButtons = this.plugin.getAddButtons(
        this.plugin.config,
        this.services
      );
    }
  }
  initTextButtons() {
    if (this.plugin.textButtons) {
      this.textButtons = this.plugin.textButtons;
    }
  }
  initPluginToolbar() {
    const toolbar = this.plugin.toolbar;
    if (!toolbar) {
      return;
    }
    this.toolbars = toolbar.names.map((name) => {
      const ricosPluginToolbar = RicosPluginToolbar.of(
        toolbar,
        name,
        this.services,
        this.plugin.config
      );
      return ricosPluginToolbar;
    });
  }
  initFloatingToolbarButton() {
    if (this.plugin.floatingToolbarButton) {
      this.floatingToolbarButton = this.plugin.floatingToolbarButton;
    }
  }
  initExports() {
    if (this.plugin.exports) {
      this.exports = this.plugin.exports;
    }
  }
  register() {
    this.plugin.shortcuts?.map((shortcut) => this.services.shortcuts.register(shortcut));
    this.initAddButtons();
    this.initTextButtons();
    this.initPluginToolbar();
    this.initFloatingToolbarButton();
    this.initExports();
  }
  unregister() {
    this.plugin.shortcuts?.forEach((shortcut) => this.services.shortcuts.unregister(shortcut));
    this.floatingToolbarButton = void 0;
    this.exports = void 0;
  }
  getType() {
    return this.plugin.type;
  }
  getTiptapExtensions() {
    return this.plugin.tiptapExtensions?.map(
      (extension) => ({
        ...extension,
        settings: this.getConfig()
      })
    );
  }
  getConfig() {
    return this.plugin.config;
  }
  getTextButtons() {
    return this.textButtons || [];
  }
  getQuickActions() {
    return this.plugin.getQuickActions?.({
      pluginServices: this.services,
      config: this.plugin.config
    }) || [];
  }
  getAddButtons() {
    return this.addButtons || [];
  }
  getToolbars() {
    return this.toolbars || [];
  }
  getFloatingToolbarButton() {
    return this.floatingToolbarButton || null;
  }
  getExports() {
    return this.exports || {};
  }
  getProvider() {
    return this.plugin.Provider || null;
  }
  getGlobalComponent() {
    return this.plugin.GlobalComponent || null;
  }
  equals(plugin) {
    return this.plugin.type === plugin.getType();
  }
}
export {
  EditorPlugin
};
//# sourceMappingURL=editor-plugin.js.map
