import { jsx as _jsx } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { createContext, useCallback, useContext, useEffect, useState, } from 'react';
import { SettingScope } from '../../config/settings.js';
const VimModeContext = createContext(undefined);
export const VimModeProvider = ({ children, settings, }) => {
    const initialVimEnabled = settings.merged.general.vimMode;
    const [vimEnabled, setVimEnabled] = useState(initialVimEnabled);
    const [vimMode, setVimMode] = useState('INSERT');
    useEffect(() => {
        // Initialize vimEnabled from settings on mount
        const enabled = settings.merged.general.vimMode;
        setVimEnabled(enabled);
        // When vim mode is enabled, start in INSERT mode
        if (enabled) {
            setVimMode('INSERT');
        }
    }, [settings.merged.general.vimMode]);
    const toggleVimEnabled = useCallback(async () => {
        const newValue = !vimEnabled;
        setVimEnabled(newValue);
        // When enabling vim mode, start in INSERT mode
        if (newValue) {
            setVimMode('INSERT');
        }
        settings.setValue(SettingScope.User, 'general.vimMode', newValue);
        return newValue;
    }, [vimEnabled, settings]);
    const value = {
        vimEnabled,
        vimMode,
        toggleVimEnabled,
        setVimMode,
    };
    return (_jsx(VimModeContext.Provider, { value: value, children: children }));
};
export const useVimMode = () => {
    const context = useContext(VimModeContext);
    if (context === undefined) {
        throw new Error('useVimMode must be used within a VimModeProvider');
    }
    return context;
};
//# sourceMappingURL=VimModeContext.js.map