import { dispatchSlashCommand } from "../slash-command-handlers.js";
export function setupEditorSubmitHandler(host) {
    host.defaultEditor.onSubmit = async (text) => {
        text = text.trim();
        if (!text)
            return;
        if (text.startsWith("/")) {
            const handled = await dispatchSlashCommand(text, host.getSlashCommandContext());
            if (handled) {
                host.editor.setText("");
                return;
            }
        }
        if (text.startsWith("!")) {
            const isExcluded = text.startsWith("!!");
            const command = isExcluded ? text.slice(2).trim() : text.slice(1).trim();
            if (command) {
                if (host.session.isBashRunning) {
                    host.showWarning("A bash command is already running. Press Esc to cancel it first.");
                    host.editor.setText(text);
                    return;
                }
                host.editor.addToHistory?.(text);
                await host.handleBashCommand(command, isExcluded);
                host.isBashMode = false;
                host.updateEditorBorderColor();
                return;
            }
        }
        if (host.session.isCompacting) {
            if (host.isExtensionCommand(text)) {
                host.editor.addToHistory?.(text);
                host.editor.setText("");
                await host.session.prompt(text);
            }
            else {
                host.queueCompactionMessage(text, "steer");
            }
            return;
        }
        if (host.session.isStreaming) {
            host.editor.addToHistory?.(text);
            host.editor.setText("");
            await host.session.prompt(text, { streamingBehavior: "steer" });
            host.updatePendingMessagesDisplay();
            host.ui.requestRender();
            return;
        }
        host.flushPendingBashComponents();
        if (host.onInputCallback) {
            host.onInputCallback(text);
            host.editor.addToHistory?.(text);
            return;
        }
        if (host.options?.submitPromptsDirectly) {
            host.editor.addToHistory?.(text);
            try {
                await host.session.prompt(text);
            }
            catch (error) {
                const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
                host.showError(errorMessage);
            }
            return;
        }
        host.editor.addToHistory?.(text);
    };
}
//# sourceMappingURL=input-controller.js.map