/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Command, defaultKeyBindingConfig, loadCustomKeybindings, } from './keyBindings.js';
/**
 * Checks if a key matches any of the bindings for a command
 */
function matchCommand(command, key, config = defaultKeyBindingConfig) {
    const bindings = config.get(command);
    if (!bindings)
        return false;
    return bindings.some((binding) => binding.matches(key));
}
/**
 * Creates key matchers from a key binding configuration
 */
export function createKeyMatchers(config = defaultKeyBindingConfig) {
    // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
    const matchers = {};
    for (const command of Object.values(Command)) {
        matchers[command] = (key) => matchCommand(command, key, config);
    }
    return matchers;
}
/**
 * Default key binding matchers using the default configuration
 */
export const defaultKeyMatchers = createKeyMatchers(defaultKeyBindingConfig);
// Re-export Command for convenience
export { Command };
/**
 * Loads and creates key matchers including user customizations.
 */
export async function loadKeyMatchers() {
    const { config, errors } = await loadCustomKeybindings();
    return {
        matchers: createKeyMatchers(config),
        errors,
    };
}
//# sourceMappingURL=keyMatchers.js.map