// Manages switching between analytical layers
class LayerManager {
    constructor(viz) {
        this.viz = viz;
        this.layers = {};
        this.activeName = null;
    }

    register(name, layer) {
        this.layers[name] = layer;
    }

    async activate(name) {
        // Deactivate current layer first
        if (this.activeName && this.layers[this.activeName]) {
            this.layers[this.activeName].deactivate();
        }

        // Clear any selected node from the previous layer/state
        this.viz.clearSelection();
        InfoPanel.clear();

        if (name === 'default' || !this.layers[name]) {
            this.viz.activeLayer = null;
            this.activeName = null;
        } else {
            const layer = this.layers[name];
            await layer.activate();
            this.viz.activeLayer = layer;
            this.activeName = name;
        }

        this.viz.render();
    }

    deactivate() {
        this.activate('default');
    }

    getActive() {
        return this.activeName ? this.layers[this.activeName] : null;
    }
}
