import { useState, useCallback } from 'react';
import { apiClient } from '../lib/api-client';
export function useCommandSuggestions({ onCommand, updatePreferences, vimModeEnabled, reasoningEnabled, textareaRef, setMessage, setShowShortcutsModal, sessionId, }) {
    const [showCommandSuggestions, setShowCommandSuggestions] = useState(false);
    const [commandQuery, setCommandQuery] = useState('');
    const [commandSelectedIndex, setCommandSelectedIndex] = useState(0);
    const [currentCommandToSelect, setCurrentCommandToSelect] = useState();
    const handleCommandSelect = useCallback(async (commandId) => {
        const resetInput = () => {
            setMessage('');
            setShowCommandSuggestions(false);
            if (textareaRef.current) {
                textareaRef.current.style.height = 'auto';
            }
            textareaRef.current?.focus();
        };
        if (commandId === 'help') {
            setShowShortcutsModal(true);
            resetInput();
            return;
        }
        if (commandId === 'vim') {
            updatePreferences({ vimMode: !vimModeEnabled });
            resetInput();
            return;
        }
        if (commandId === 'reasoning') {
            updatePreferences({ reasoningEnabled: !reasoningEnabled });
            resetInput();
            return;
        }
        if (commandId === 'stop') {
            if (sessionId) {
                try {
                    await apiClient.abortSession(sessionId);
                }
                catch (error) {
                    console.error('Failed to stop generation:', error);
                }
            }
            resetInput();
            return;
        }
        if (onCommand) {
            onCommand(commandId);
        }
        resetInput();
    }, [
        onCommand,
        vimModeEnabled,
        reasoningEnabled,
        updatePreferences,
        textareaRef,
        setMessage,
        setShowShortcutsModal,
        sessionId,
    ]);
    const handleCommandEnterSelect = useCallback((commandId) => {
        setCurrentCommandToSelect(commandId);
    }, []);
    const checkForCommand = useCallback((value) => {
        if (value.startsWith('/') && !value.includes(' ')) {
            setShowCommandSuggestions(true);
            setCommandQuery(value.slice(1));
            setCommandSelectedIndex(0);
        }
        else {
            setShowCommandSuggestions(false);
        }
    }, []);
    return {
        showCommandSuggestions,
        commandQuery,
        commandSelectedIndex,
        currentCommandToSelect,
        setShowCommandSuggestions,
        setCommandQuery,
        setCommandSelectedIndex,
        setCurrentCommandToSelect,
        handleCommandSelect,
        handleCommandEnterSelect,
        checkForCommand,
    };
}
//# sourceMappingURL=useCommandSuggestions.js.map