import '../node_modules/monaco-vim/lib/index.js';
import { configurationRegistry } from '@codingame/monaco-vscode-configuration-service-override';
import { onConfigurationChanged, getConfiguration } from '../configuration/index.js';
import { __exports as lib } from '../_virtual/index.js';

const vimKeybindingsSchema = {
    type: 'object',
    properties: {
        before: {
            type: 'array',
            items: {
                type: 'string'
            }
        },
        after: {
            type: 'array',
            items: {
                type: 'string'
            }
        }
    }
};
configurationRegistry.registerConfiguration({
    id: 'vim',
    order: 5,
    type: 'object',
    title: 'Vim',
    scope: 5 /* ConfigurationScope.LANGUAGE_OVERRIDABLE */,
    properties: {
        'vim.normalModeKeyBindings': {
            type: 'array',
            description: 'Remapped keys in Normal mode.',
            items: vimKeybindingsSchema
        },
        'vim.insertModeKeyBindings': {
            type: 'array',
            description: 'Remapped keys in Insert mode.',
            items: vimKeybindingsSchema
        },
        'vim.visualModeKeyBindings': {
            type: 'array',
            description: 'Remapped keys in Visual mode.',
            items: vimKeybindingsSchema
        }
    }
});
function mapVimKeyBindings(keybindingConfig, mode) {
    if (keybindingConfig != null) {
        for (const item of keybindingConfig) {
            if (item.after != null && item.before != null) {
                lib.VimMode.Vim.map(item.before.join(''), item.after.join(''), mode);
            }
        }
    }
}
function unmapVimKeyBindings(keybindingConfig, mode) {
    if (keybindingConfig != null) {
        for (const item of keybindingConfig) {
            if (item.after != null && item.before != null) {
                lib.VimMode.Vim.unmap(item.before.join(''), mode);
            }
        }
    }
}
let unmapPrevious = () => { };
onConfigurationChanged(() => {
    unmapPrevious();
    const config = getConfiguration(undefined, 'vim');
    mapVimKeyBindings(config?.insertModeKeyBindings, 'insert');
    mapVimKeyBindings(config?.normalModeKeyBindings, 'normal');
    mapVimKeyBindings(config?.visualModeKeyBindings, 'visual');
    unmapPrevious = () => {
        unmapVimKeyBindings(config?.insertModeKeyBindings, 'insert');
        unmapVimKeyBindings(config?.normalModeKeyBindings, 'normal');
        unmapVimKeyBindings(config?.visualModeKeyBindings, 'visual');
    };
});
function initVimMode(editor, statusBarElement) {
    return lib.initVimMode(editor, statusBarElement);
}

export { initVimMode };
