import { highlightActiveLineGutter, highlightSpecialChars, drawSelection, dropCursor, rectangularSelection, crosshairCursor, highlightActiveLine, keymap, } from '@codemirror/view';
import { EditorState } from '@codemirror/state';
import { history, defaultKeymap, historyKeymap } from '@codemirror/commands';
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
import { closeBrackets, autocompletion, closeBracketsKeymap, } from '@codemirror/autocomplete';
import { foldGutter, indentOnInput, bracketMatching, indentUnit, foldKeymap, } from '@codemirror/language';
import { lintKeymap } from '@codemirror/lint';
export const isValidSetup = (item) => {
    return typeof item === 'undefined' || item;
};
export const basicSetup = (options = {}) => {
    const { crosshairCursor: initCrosshairCursor = false } = options;
    let keymaps = [];
    isValidSetup(options.defaultKeymap) && keymaps.push(...defaultKeymap);
    isValidSetup(options.closeBracketsKeymap) && keymaps.push(...closeBracketsKeymap);
    isValidSetup(options.searchKeymap) && keymaps.push(...searchKeymap);
    isValidSetup(options.historyKeymap) && keymaps.push(...historyKeymap);
    isValidSetup(options.foldKeymap) && keymaps.push(...foldKeymap);
    isValidSetup(options.lintKeymap) && keymaps.push(...lintKeymap);
    const extensions = [];
    isValidSetup(options.highlightActiveLineGutter) && extensions.push(highlightActiveLineGutter());
    isValidSetup(options.highlightSpecialChars) && extensions.push(highlightSpecialChars());
    isValidSetup(options.history) && extensions.push(history());
    isValidSetup(options.foldGutter) && extensions.push(foldGutter());
    isValidSetup(options.drawSelection) && extensions.push(drawSelection());
    isValidSetup(options.dropCursor) && extensions.push(dropCursor());
    isValidSetup(options.allowMultipleSelections) && extensions.push(EditorState.allowMultipleSelections.of(true));
    isValidSetup(options.indentOnInput) && extensions.push(indentOnInput());
    isValidSetup(options.bracketMatching) && extensions.push(bracketMatching());
    isValidSetup(options.closeBrackets) && extensions.push(closeBrackets());
    isValidSetup(options.autocompletion) && extensions.push(autocompletion());
    isValidSetup(options.rectangularSelection) && extensions.push(rectangularSelection());
    isValidSetup(options.crosshairCursor) && extensions.push(crosshairCursor());
    isValidSetup(options.highlightActiveLine) && extensions.push(highlightActiveLine());
    isValidSetup(options.highlightSelectionMatches) && extensions.push(highlightSelectionMatches());
    if (!options.enableSearch) {
        extensions.push(keymap.of([{
                key: "Mod-f", // Ctrl+F (Cmd+F on Mac)
                run: () => {
                    return true;
                }
            }]));
    }
    if (options.tabSize && typeof options.tabSize === 'number')
        extensions.push(indentUnit.of(' '.repeat(options.tabSize)));
    return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
};
//# sourceMappingURL=extensionSetup.js.map