/**
 * WorkspaceRegistry manages registration and lookup of workspaces.
 *
 * Workspaces are fundamentally different UI experiences (home, editor, settings, etc.).
 * This registry provides a clean API for registering workspaces from core and plugins.
 */
export class WorkspaceRegistry {
    workspaces = new Map();
    /**
     * Register a workspace definition.
     * @param workspace The workspace definition to register
     * @throws Error if a workspace with the same ID already exists
     */
    register(workspace) {
        if (this.workspaces.has(workspace.id)) {
            console.warn(`WorkspaceRegistry: Workspace "${workspace.id}" is already registered. Overwriting.`);
        }
        this.workspaces.set(workspace.id, workspace);
    }
    /**
     * Register multiple workspaces at once.
     * @param workspaces Array of workspace definitions
     */
    registerAll(workspaces) {
        for (const workspace of workspaces) {
            this.register(workspace);
        }
    }
    /**
     * Get a workspace by ID.
     * @param id The workspace ID
     * @returns The workspace definition or undefined if not found
     */
    get(id) {
        return this.workspaces.get(id);
    }
    /**
     * Get all registered workspaces.
     * @returns Array of all workspace definitions
     */
    getAll() {
        return Array.from(this.workspaces.values());
    }
    /**
     * Get all visible workspaces for the current context.
     * Filters out hidden workspaces and those whose visible() returns false.
     * Sorted by sortOrder (lower numbers first).
     * @param editContext The current edit context
     * @returns Array of visible workspace definitions, sorted by sortOrder
     */
    getVisible(editContext) {
        return this.getAll()
            .filter((workspace) => {
            // Filter out hidden workspaces
            if (workspace.hidden)
                return false;
            // Check dynamic visibility
            if (workspace.visible && !workspace.visible(editContext))
                return false;
            return true;
        })
            .sort((a, b) => (a.sortOrder ?? 100) - (b.sortOrder ?? 100));
    }
    /**
     * Check if a workspace exists.
     * @param id The workspace ID
     * @returns True if the workspace is registered
     */
    has(id) {
        return this.workspaces.has(id);
    }
    /**
     * Remove a workspace by ID.
     * @param id The workspace ID to remove
     * @returns True if the workspace was removed
     */
    unregister(id) {
        return this.workspaces.delete(id);
    }
    /**
     * Clear all registered workspaces.
     */
    clear() {
        this.workspaces.clear();
    }
    /**
     * Get the count of registered workspaces.
     */
    get size() {
        return this.workspaces.size;
    }
}
// Global singleton instance
let globalWorkspaceRegistry = null;
/**
 * Get the global workspace registry instance.
 * Creates it if it doesn't exist.
 */
export function getWorkspaceRegistry() {
    if (!globalWorkspaceRegistry) {
        globalWorkspaceRegistry = new WorkspaceRegistry();
    }
    return globalWorkspaceRegistry;
}
/**
 * Reset the global workspace registry.
 * Useful for testing.
 */
export function resetWorkspaceRegistry() {
    globalWorkspaceRegistry = null;
}
//# sourceMappingURL=WorkspaceRegistry.js.map