import { jsx as _jsx } from "react/jsx-runtime";
import { useState } from 'react';
import { ReadRenderer } from './ReadRenderer';
import { WriteRenderer } from './WriteRenderer';
import { EditRenderer } from './EditRenderer';
import { BashRenderer } from './BashRenderer';
import { GitStatusRenderer } from './GitStatusRenderer';
import { GitDiffRenderer } from './GitDiffRenderer';
import { GitCommitRenderer } from './GitCommitRenderer';
import { ApplyPatchRenderer } from './ApplyPatchRenderer';
import { ListRenderer } from './ListRenderer';
import { TreeRenderer } from './TreeRenderer';
import { SearchRenderer } from './SearchRenderer';
import { FinishRenderer } from './FinishRenderer';
import { GenericRenderer } from './GenericRenderer';
import { DebugRenderer } from './DebugRenderer';
import { TodosRenderer } from './TodosRenderer';
import { ProgressUpdateRenderer } from './ProgressUpdateRenderer';
import { WebSearchRenderer } from './WebSearchRenderer';
import { ErrorRenderer } from './ErrorRenderer';
import { DatabaseToolRenderer } from './DatabaseToolRenderer';
/**
 * Normalize tool names to canonical form for rendering.
 * Handles both snake_case (canonical) and PascalCase (OAuth) names.
 */
const TOOL_NAME_ALIASES = {
    Read: 'read',
    Write: 'write',
    Edit: 'edit',
    Ls: 'ls',
    Tree: 'tree',
    Cd: 'cd',
    Pwd: 'pwd',
    Glob: 'glob',
    Grep: 'ripgrep',
    Bash: 'bash',
    Terminal: 'terminal',
    GitStatus: 'git_status',
    GitDiff: 'git_diff',
    GitCommit: 'git_commit',
    ApplyPatch: 'apply_patch',
    UpdateTodos: 'update_todos',
    UpdatePlan: 'update_todos',
    ProgressUpdate: 'progress_update',
    Finish: 'finish',
    WebSearch: 'websearch',
};
function normalizeToolName(name) {
    return TOOL_NAME_ALIASES[name] ?? name;
}
export function ToolResultRenderer({ toolName, contentJson, toolDurationMs, debug, onNavigateToSession, compact, sessionId, onRetry, }) {
    const [isExpanded, setIsExpanded] = useState(false);
    const normalizedName = normalizeToolName(toolName);
    const handleToggle = () => setIsExpanded(!isExpanded);
    const props = {
        contentJson,
        toolDurationMs: toolDurationMs ?? undefined,
        isExpanded,
        onToggle: handleToggle,
        compact,
    };
    if (debug) {
        return _jsx(DebugRenderer, { ...props, toolName: toolName });
    }
    switch (normalizedName) {
        case 'read':
            return _jsx(ReadRenderer, { ...props });
        case 'write':
            return _jsx(WriteRenderer, { ...props });
        case 'edit':
            return _jsx(EditRenderer, { ...props });
        case 'bash':
            return _jsx(BashRenderer, { ...props });
        case 'git_status':
            return _jsx(GitStatusRenderer, { ...props });
        case 'git_diff':
            return _jsx(GitDiffRenderer, { ...props });
        case 'git_commit':
            return _jsx(GitCommitRenderer, { ...props });
        case 'apply_patch':
            return _jsx(ApplyPatchRenderer, { ...props });
        case 'ls':
            return _jsx(ListRenderer, { ...props });
        case 'tree':
            return _jsx(TreeRenderer, { ...props });
        case 'ripgrep':
        case 'grep':
        case 'glob':
            return _jsx(SearchRenderer, { ...props });
        case 'websearch':
            return _jsx(WebSearchRenderer, { ...props });
        case 'finish':
            return _jsx(FinishRenderer, { ...props });
        case 'update_todos':
        case 'update_plan':
            return _jsx(TodosRenderer, { ...props });
        case 'progress_update':
            return _jsx(ProgressUpdateRenderer, { ...props });
        case 'error':
            return (_jsx(ErrorRenderer, { ...props, sessionId: sessionId, onRetry: onRetry }));
        case 'query_sessions':
        case 'query_messages':
        case 'search_history':
        case 'get_session_context':
        case 'get_parent_session':
        case 'present_action':
            return (_jsx(DatabaseToolRenderer, { toolName: toolName, ...props, onNavigateToSession: onNavigateToSession }));
        default:
            return _jsx(GenericRenderer, { ...props, toolName: toolName });
    }
}
export * from './types';
export { ReasoningRenderer } from './ReasoningRenderer';
//# sourceMappingURL=index.js.map