import getExtensionServiceOverride from '@codingame/monaco-vscode-extensions-service-override';
import getModelServiceOverride from '@codingame/monaco-vscode-model-service-override';
import getDialogsServiceOverride from '@codingame/monaco-vscode-dialogs-service-override';
import getConfigurationServiceOverride from '@codingame/monaco-vscode-configuration-service-override';
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
import getLanguagesServiceOverride from '@codingame/monaco-vscode-languages-service-override';
import getAudioCueServiceOverride from '@codingame/monaco-vscode-audio-cue-service-override';
import getPreferencesServiceOverride from '@codingame/monaco-vscode-preferences-service-override';
import getSnippetServiceOverride from '@codingame/monaco-vscode-snippets-service-override';
import getAccessibilityServiceOverride from '@codingame/monaco-vscode-accessibility-service-override';
import getLanguageDetectionWorkerServiceOverride from '@codingame/monaco-vscode-language-detection-worker-service-override';
import getEditorServiceOverride from '@codingame/monaco-vscode-editor-service-override';
import getStorageServiceOverride from '@codingame/monaco-vscode-storage-service-override';
import getLifecycleServiceOverride from '@codingame/monaco-vscode-lifecycle-service-override';
import getQuickAccessServiceOverride from '@codingame/monaco-vscode-quickaccess-service-override';
import getLogServiceOverride from '@codingame/monaco-vscode-log-service-override';
import getWorkingCopyServiceOverride from '@codingame/monaco-vscode-working-copy-service-override';
import { initialize as initialize$1, StandaloneServices, ILogService, LogLevel } from 'vscode/services';
import * as monaco from 'monaco-editor';
import { initFile } from '@codingame/monaco-vscode-files-service-override';
import EditorOpenHandlerRegistry from './tools/EditorOpenHandlerRegistry.js';
import { whenReady } from './extensions.js';
import 'vscode/localExtensionHost';

const editorOpenHandlerRegistry = new EditorOpenHandlerRegistry();
let _useGlobalPicker = false;
function setUseGlobalPicker(useGlobalPicker = true) {
    _useGlobalPicker = useGlobalPicker;
}
function useGlobalPicker() {
    // should picker and keybindings be global or per-editor
    return _useGlobalPicker;
}
let services = {
    ...getLogServiceOverride(),
    ...getExtensionServiceOverride(),
    ...getModelServiceOverride(),
    ...getDialogsServiceOverride(),
    ...getConfigurationServiceOverride(),
    ...getKeybindingsServiceOverride({
        shouldUseGlobalKeybindings() {
            return useGlobalPicker();
        }
    }),
    ...getTextmateServiceOverride(),
    ...getThemeServiceOverride(),
    ...getLanguagesServiceOverride(),
    ...getAudioCueServiceOverride(),
    ...getPreferencesServiceOverride(),
    ...getSnippetServiceOverride(),
    ...getLanguageDetectionWorkerServiceOverride(),
    ...getEditorServiceOverride((model, input, sideBySide) => {
        return editorOpenHandlerRegistry.openCodeEditor(model, input, sideBySide);
    }),
    ...getAccessibilityServiceOverride(),
    ...getStorageServiceOverride(),
    ...getLifecycleServiceOverride(),
    ...getQuickAccessServiceOverride({
        shouldUseGlobalPicker() {
            return useGlobalPicker();
        }
    }),
    ...getWorkingCopyServiceOverride()
};
function registerServices(newServices) {
    services = {
        ...services,
        ...newServices
    };
}
async function initialize() {
    // wait a short time for the services to be registered
    await new Promise(resolve => setTimeout(resolve, 0));
    const workspaceFile = monaco.Uri.file('/workspace.code-workspace');
    await initFile(workspaceFile, JSON.stringify({
        folders: [{
                path: '/tmp/project'
            }]
    }));
    await initialize$1(services, undefined, { workspaceProvider: { open: async () => false, workspace: { workspaceUri: workspaceFile }, trusted: true } });
    StandaloneServices.get(ILogService).setLevel(LogLevel.Off);
    await whenReady();
}

export { editorOpenHandlerRegistry, initialize, registerServices, setUseGlobalPicker, useGlobalPicker };
