import type { RunPhase } from "../types/runPhase";

const TOOL_LABELS: Record<string, string> = {
	Read: "读取文件",
	Write: "写入文件",
	Edit: "编辑文件",
	Grep: "搜索代码",
	Glob: "查找文件",
	Shell: "执行命令",
	Task: "启动子任务",
	WebSearch: "搜索网页",
	WebFetch: "获取网页",
	SemanticSearch: "语义搜索",
	Delete: "删除文件",
	AskQuestion: "等待确认",
};

function formatToolDetail(name: string): string {
	const trimmed = name.trim();
	if (!trimmed) return "工具";
	return TOOL_LABELS[trimmed] ?? trimmed;
}

export function formatRunPhaseLabel(phase: RunPhase, detail?: string): string {
	switch (phase) {
		case "starting":
			return "等待模型响应…";
		case "thinking":
			return "思考中…";
		case "writing":
			return "撰写回复中…";
		case "tool":
			return `调用 ${formatToolDetail(detail ?? "工具")}…`;
		case "bash":
			return "运行命令…";
		case "processing":
			return "处理结果中…";
		default:
			return "生成中…";
	}
}
