// The plugin manager
export class OrderlyExtensionRegistry {
    static _instance;
    static getInstance() {
        if (!OrderlyExtensionRegistry._instance) {
            OrderlyExtensionRegistry._instance = new OrderlyExtensionRegistry();
        }
        return OrderlyExtensionRegistry._instance;
    }
    extensionMap = new Map();
    register(plugin) {
        // this.pluginMap.set(plugin.name, plugin);
        for(let index = 0; index < plugin.positions.length; index++){
            const pos = plugin.positions[index];
            this.registerToPosition(pos, plugin);
        }
    }
    registerToPosition(position, plugin) {
        if (this.extensionMap.has(position)) {
            const existingPlugin = this.extensionMap.get(position);
            if (!existingPlugin?.__isInternal) {
                throw new Error(`Plugin already registered at position [${position}]`);
            }
        }
        this.extensionMap.set(position, plugin);
    }
    unregister(plugin) {
        for(let index = 0; index < plugin.positions.length; index++){
            const pos = plugin.positions[index];
            this.unregisterFromPosition(pos);
        }
    }
    unregisterFromPosition(position) {
        this.extensionMap.delete(position);
    }
    getPluginsByPosition(position) {
        return this.extensionMap.get(position);
    }
}

//# sourceMappingURL=registry.js.map