import { Emitter, Disposable } from '@difizen/mana-common';
import type { Contribution } from '@difizen/mana-syringe';
import { Syringe } from '@difizen/mana-syringe';
import { ApplicationContribution } from '../application/application';
import type { CommandEvent, CommandHandler, CommandHandlerWithContext, ActiveHandler, EnabledHandler, VisibleHandler, WillExecuteCommandEvent, ExecuteHandler } from './command-protocol';
import { Command, CommandService } from './command-protocol';
export declare const CommandContribution: Syringe.DefinedToken;
/**
 * The command contribution should be implemented to register custom commands and handler.
 */
export type CommandContribution = {
    /**
     * Register commands and handlers.
     */
    registerCommands: (commands: CommandRegistry) => void;
};
/**
 * The command registry manages commands and handlers.
 */
export declare class CommandRegistry implements CommandService, ApplicationContribution {
    readonly commandMap: Record<string, Command>;
    readonly ctxMap: Record<string, any>;
    protected readonly _handlers: Record<string, CommandHandler[]>;
    protected readonly toUnregisterCommands: Map<string, Disposable>;
    protected recent: Command[];
    protected readonly onWillExecuteCommandEmitter: Emitter<WillExecuteCommandEvent>;
    readonly onWillExecuteCommand: import("@difizen/mana-common").Event<WillExecuteCommandEvent>;
    protected readonly onDidExecuteCommandEmitter: Emitter<CommandEvent>;
    readonly onDidExecuteCommand: import("@difizen/mana-common").Event<CommandEvent>;
    protected readonly contributionProvider: Contribution.Provider<CommandContribution>;
    constructor(contributionProvider: Contribution.Provider<CommandContribution>);
    onStart(): void;
    /**
     * Register the given command and handler if present.
     *
     * Throw if a command is already registered for the given command identifier.
     */
    registerCommand(command: Command, handler?: CommandHandler): Disposable;
    /**
     * Register the given command with context, and handler if present.
     *
     * Throw if a command is already registered for the given command identifier.
     */
    registerCommandWithContext<T = any>(command: Command, ctx: T, handler?: CommandHandlerWithContext<T>): Disposable;
    protected doRegisterCommandCtx(command: Command, ctx: any): Disposable;
    protected doRegisterCommand(command: Command): Disposable;
    /**
     * Unregister command from the registry
     *
     * @param command
     */
    unregisterCommand(command: Command): void;
    /**
     * Unregister command from the registry
     *
     * @param id
     */
    unregisterCommand(id: string): void;
    /**
     * Register the given handler for the given command identifier.
     *
     * If there is already a handler for the given command
     * then the given handler is registered as more specific, and
     * has higher priority during enablement, visibility and toggle state evaluations.
     */
    registerHandler(commandId: string, handler: CommandHandler): Disposable;
    /**
     * Test whether there is an active handler for the given command.
     */
    isEnabled(command: string, ...args: any[]): boolean;
    /**
     * Test whether there is a visible handler for the given command.
     */
    isVisible(command: string, ...args: any[]): boolean;
    /**
     * Test whether there is a active handler for the given command.
     */
    isActive(command: string, ...args: any[]): boolean;
    toContextArgs(commandId: string, ...args: any[]): any[];
    /**
     * Test whether there is an active handler for the given command.
     */
    isEnabledByHandler(handler: EnabledHandler, command: string, ...args: any[]): boolean;
    /**
     * Test whether there is a visible handler for the given command.
     */
    isVisibleByHandler(handler: VisibleHandler, command: string, ...args: any[]): boolean;
    /**
     * Test whether there is a active handler for the given command.
     */
    isActiveByHandler(handler: ActiveHandler, command: string, ...args: any[]): boolean;
    /**
     * Execute the given handler for the given command and arguments.
     */
    executeCommandByHandler<T>(handler: ExecuteHandler, command: string, ...args: any[]): Promise<T | undefined>;
    /**
     * Execute the active handler for the given command and arguments.
     *
     * Reject if a command cannot be executed.
     */
    executeCommand<T>(commandId: string, ...args: any[]): Promise<T | undefined>;
    protected fireWillExecuteCommand(commandId: string, args?: any[]): Promise<void>;
    /**
     * Get a visible handler for the given command or `undefined`.
     */
    getVisibleHandler(commandId: string, ...args: any[]): CommandHandler | undefined;
    /**
     * Get an enable handler for the given command or `undefined`.
     */
    getEnableHandler(commandId: string, ...args: any[]): CommandHandler | undefined;
    /**
     * Get an active handler for the given command or `undefined`.
     */
    getActiveHandler(commandId: string, ...args: any[]): CommandHandler | undefined;
    /**
     * Returns with all handlers for the given command. If the command does not have any handlers,
     * or the command is not registered, returns an empty array.
     */
    getAllHandlers(commandId: string): CommandHandler[];
    /**
     * Get all registered commands.
     */
    get commands(): Command[];
    /**
     * Get a command for the given command identifier.
     */
    getCommand(id: string): Command | undefined;
    /**
     * Get all registered commands identifiers.
     */
    get commandIds(): string[];
    /**
     * Adds a command to recently used list.
     * Prioritizes commands that were recently executed to be most recent.
     *
     * @param recent a recent command, or array of recent commands.
     */
    addRecentCommand(recent: Command | Command[]): void;
    /**
     * Clear the list of recently used commands.
     */
    clearCommandHistory(): void;
}
//# sourceMappingURL=command-registry.d.ts.map