import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { SelectList } from "../design/SelectList.js";
import { truncateCells } from "../design/textLayout.js";
export function MCPToolListView(props) {
    const model = mcpToolListModel(props.serverName, props.tools);
    const width = props.width ?? 96;
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: "cyan", children: truncateCells(model.title, width) }), _jsx(Text, { color: "gray", children: truncateCells(model.subtitle, width) }), _jsx(SelectList, { options: model.options, selectedIndex: props.selectedIndex, width: width })] }));
}
export function mcpToolListModel(serverName, tools) {
    return {
        title: `Tools for ${serverName}`,
        subtitle: `${tools.length} available tool${tools.length === 1 ? "" : "s"}`,
        options: tools.map((tool, index) => ({
            id: `${serverName}:${tool.name}:${index}`,
            label: displayToolName(tool.name, serverName),
            detail: tool.description ?? "no description",
            description: toolAnnotations(tool).join(", "),
            selected: index === 0,
            tone: tool.destructive ? "error" : tool.readOnly ? "success" : "brand",
        })),
    };
}
export function displayToolName(name, serverName) {
    const prefixes = [`mcp__${serverName}__`, `${serverName}__`, `${serverName}.`];
    for (const prefix of prefixes) {
        if (name.startsWith(prefix))
            return name.slice(prefix.length);
    }
    return name;
}
function toolAnnotations(tool) {
    return [
        tool.readOnly ? "read-only" : "",
        tool.destructive ? "destructive" : "",
        tool.openWorld ? "open-world" : "",
    ].filter(Boolean);
}
