/**
 * Tool presentation registry — maps tool names to their render functions.
 *
 * Each case in the switch statement wires a tool name to its renderCall/renderResult/renderGroup
 * implementations from the renderers/ directory. This is the single source of truth
 * for how every built-in tool is displayed in the TUI.
 */
import { resolveTaskQuery } from '../../../app/tools/task/query.js';
import { ACTION_SWITCH_MODE, BASH, EDIT, EXECUTE_CODE, EXECUTE_TOOL, FIND, GET_TOOL_INFO, GREP, INSTALLATION_SWITCH_MODE, LLM_ANALYSIS, LS, PLAN_SWITCH_MODE, READ, SEND_MESSAGE, WEB_SEARCH, WRITE } from '../../../tool-names.js';
import { renderBashCall, renderBashResult } from './renderers/bash.js';
import { renderCodeExecCall } from './renderers/code-exec.js';
import { renderEditCall, renderEditResult, renderReadCall, renderReadResult, renderWriteCall, renderWriteResult } from './renderers/file-ops.js';
import { renderFindCall, renderFindResult, renderGrepCall, renderGrepResult, renderLsCall, renderLsResult } from './renderers/search-ops.js';
import { renderTaskCall, renderTaskGroup, renderTaskResult } from './renderers/task.js';
import { renderExecuteToolCall, renderExecuteToolResult, renderGetToolInfoCall, renderHiddenExpandedResult, renderLlmAnalysisCall, renderMcpDescribeCall, renderMcpExecuteCall, renderSendMessageCall, renderSendMessageResult, renderSwitchModeCall, renderSwitchModeResult, renderTextResult } from './renderers/tool-meta.js';
import { renderWebSearchCall, renderWebSearchResult } from './renderers/web-search.js';
/** Look up the presentation for a tool by name, returning undefined for unknown tools. */
export function lookupToolPresentation(toolName, tool) {
    const resolvedName = toolName ?? tool?.name;
    if (!resolvedName)
        return undefined;
    switch (resolvedName) {
        case BASH:
            return {
                renderCall(args, options, theme) {
                    return renderBashCall(args, options.expanded, theme);
                },
                renderResult(result, options, theme) {
                    return renderBashResult(result, options.expanded, options.textOutput ?? '', options.terminalColumns ?? 80, theme);
                }
            };
        case READ:
            return {
                renderCall(args, _options, theme) {
                    return renderReadCall(args, theme);
                },
                renderResult(result, options, theme) {
                    return renderReadResult(options.args, result, options.expanded, options.textOutput ?? '', theme);
                }
            };
        case WRITE:
            return {
                renderCall(args, options, theme) {
                    return renderWriteCall(args, options.expanded, options.preview, theme);
                },
                renderResult(result, options, theme) {
                    return renderWriteResult(result, options.textOutput ?? '', theme);
                }
            };
        case EDIT:
            return {
                renderCall(args, options, theme) {
                    return renderEditCall(args, options.preview, theme);
                },
                renderResult(result, options, theme) {
                    return renderEditResult(options.args, result, options.expanded, options.textOutput ?? '', options.preview, theme);
                }
            };
        case LS:
            return {
                renderCall(args, _options, theme) {
                    return renderLsCall(args, theme);
                },
                renderResult(result, options, theme) {
                    return renderLsResult(result, options.expanded, options.textOutput ?? '', theme);
                }
            };
        case FIND:
            return {
                renderCall(args, _options, theme) {
                    return renderFindCall(args, theme);
                },
                renderResult(result, options, theme) {
                    return renderFindResult(result, options.expanded, options.textOutput ?? '', theme);
                }
            };
        case GREP:
            return {
                renderCall(args, _options, theme) {
                    return renderGrepCall(args, theme);
                },
                renderResult(result, options, theme) {
                    return renderGrepResult(result, options.expanded, options.textOutput ?? '', theme);
                }
            };
        case EXECUTE_CODE:
            return {
                renderCall(args, options, theme) {
                    return renderCodeExecCall(args, options.expanded, theme, {
                        collapsedIcon: '𝕏',
                        emptyLabel: 'execute_code'
                    });
                },
                renderResult(result, options, theme) {
                    return renderTextResult(result, options.expanded, theme);
                }
            };
        case EXECUTE_TOOL:
            return {
                renderCall(args, options, theme) {
                    return renderExecuteToolCall(args, options.expanded, theme);
                },
                renderResult(result, options, theme) {
                    return renderExecuteToolResult(result, options.expanded, theme);
                }
            };
        case GET_TOOL_INFO:
            return {
                renderCall(args, _options, theme) {
                    return renderGetToolInfoCall(args, theme);
                },
                renderResult(_result, options) {
                    return renderHiddenExpandedResult(options.expanded);
                }
            };
        case LLM_ANALYSIS:
            return {
                renderCall(args, options, theme) {
                    return renderLlmAnalysisCall(args, options.expanded, theme, 'gemini-3-flash-preview');
                },
                renderResult(result, options, theme) {
                    return renderTextResult(result, options.expanded, theme);
                }
            };
        case WEB_SEARCH:
            return {
                renderCall(args, options, theme) {
                    return renderWebSearchCall(args, options.expanded, theme);
                },
                renderResult(result, options, theme) {
                    return renderWebSearchResult(result, options.expanded, theme);
                }
            };
        case ACTION_SWITCH_MODE:
        case PLAN_SWITCH_MODE:
        case INSTALLATION_SWITCH_MODE:
            return {
                renderCall(args, options, theme) {
                    return renderSwitchModeCall(args, options.expanded, theme);
                },
                renderResult(result, _options, theme) {
                    return renderSwitchModeResult(result, theme);
                }
            };
        case SEND_MESSAGE:
            return {
                renderCall(args, _options, theme) {
                    return renderSendMessageCall(args, theme);
                },
                renderResult(result, _options, theme) {
                    return renderSendMessageResult(result, theme);
                }
            };
        case 'mcp_describe':
            return {
                renderCall(args, _options, theme) {
                    return renderMcpDescribeCall(args, theme);
                },
                renderResult(result, options, theme) {
                    return renderTextResult(result, options.expanded, theme);
                }
            };
        case 'mcp':
            return {
                renderCall(args, options, theme) {
                    return renderMcpExecuteCall(args, options.expanded, theme);
                },
                renderResult(result, options, theme) {
                    return renderTextResult(result, options.expanded, theme);
                }
            };
        case 'task':
            return {
                renderCall(args, options, theme) {
                    const parsedArgs = args;
                    const name = parsedArgs.name ?? 'task';
                    const agentType = parsedArgs.subagent_type;
                    const rawQuery = parsedArgs.query;
                    const query = rawQuery ? resolveTaskQuery(rawQuery) : undefined;
                    const label = agentType ? `${name} [${agentType}]` : name;
                    return renderTaskCall({ name: label, query }, options.expanded, theme);
                },
                renderResult(result, options, theme) {
                    const renderResult = result ?? { content: [], details: undefined };
                    const details = renderResult.details;
                    if (!details) {
                        const textBlock = renderResult.content?.[0];
                        const fallback = textBlock?.type === 'text' ? textBlock.text : '(no output)';
                        return renderTaskResult({
                            text: fallback,
                            toolCalls: [],
                            usage: {
                                input: 0,
                                output: 0,
                                cacheRead: 0,
                                cacheWrite: 0,
                                cost: 0,
                                turns: 0,
                                lastTurnInput: 0
                            },
                            isRunning: false,
                            isError: false
                        }, options.expanded, theme);
                    }
                    return renderTaskResult(details, options.expanded, theme);
                },
                renderGroup(members, options, theme) {
                    const resolved = members.map((member) => {
                        const args = (member.args ?? {});
                        const rawQuery = args.query;
                        if (!rawQuery)
                            return member;
                        const query = resolveTaskQuery(rawQuery);
                        if (query === rawQuery)
                            return member;
                        return { ...member, args: { ...args, query } };
                    });
                    return renderTaskGroup(resolved, options, theme);
                }
            };
        default:
            return undefined;
    }
}
//# sourceMappingURL=registry.js.map