/**
 * RTEDTORendererManager is a singleton class that manages the registration and retrieval of RTE DTO renderers.
 */
class RTEDTORendererManager {
  constructor() {
    // Register RTE DTO renderers, mapping type strings to their respective renderer instances.
    this.RTE_DTO_RENDERER_MAP = new Map();
    // Register RTE Toolbar Button Renderers, mapping type strings to their respective renderer instances.
    this.RTE_TOOLBAR_BUTTON_RENDERER_MAP = new Map();
  }
  /**
   * Registers a new RTE DTO renderer.
   *
   * @param {string} type - The type identifier for the RTE DTO renderer.
   * @param {VegaRTEBaseRenderer} RTEDTORenderer - The renderer instance for the RTE DTO.
   */
  registerRTEDTORenderer(type, RTEDTORenderer) {
    const existRenderer = this.RTE_DTO_RENDERER_MAP.get(type);
    if (RTEDTORenderer &&
      existRenderer &&
      existRenderer.constructor.name !== RTEDTORenderer.constructor.name) {
      throw new Error(`Renderer for type ${type} is already registered with a different class(${existRenderer.constructor.name}).`);
    }
    this.RTE_DTO_RENDERER_MAP.set(type, RTEDTORenderer);
  }
  /**
   * Registers a new RTE Toolbar Button Renderer.
   *
   * @param {string} type - The type identifier for the RTE Toolbar Button Renderer.
   * @param {VegaRTEToolbarButtonRenderer} RTEToolbarButtonRenderer - The renderer instance for the RTE Toolbar Button.
   */
  registerRTEToolbarButtonRenderer(type, RTEToolbarButtonRenderer) {
    this.RTE_TOOLBAR_BUTTON_RENDERER_MAP.set(type, RTEToolbarButtonRenderer);
  }
  /**
   * Retrieves the RTE renderer for a given type.
   *
   * @param {string} type - The type identifier for the RTE block.
   * @returns {Nullable<BaseRenderer>} - The renderer instance for the RTE block, or null if not found.
   */
  getRTERenderer(type) {
    return this.RTE_DTO_RENDERER_MAP.get(type);
  }
  /**
   * Retrieves the RTE Toolbar Button Renderer for a given type.
   *
   * @param {string} type - The type identifier for the RTE Toolbar Button Renderer.
   * @returns {Nullable<VegaRTEToolbarButtonRenderer>} - The renderer instance for the RTE Toolbar Button, or null if not found.
   */
  getRTEToolbarButtonRenderer(type) {
    return this.RTE_TOOLBAR_BUTTON_RENDERER_MAP.get(type);
  }
}
export default new RTEDTORendererManager();
