import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { Pane } from "../design/Pane.js";
import { StatusBadge } from "../design/StatusBadge.js";
import { truncateCells } from "../design/textLayout.js";
import { agentPathLabel } from "./agentFileUtils.js";
import { agentScopeTone, compactAgentDescription, summarizeAgentTools } from "./utils.js";
export function agentDetailModel(input) {
    const width = input.width ?? 88;
    const agent = input.agent;
    const promptPreview = agent.prompt
        .split(/\r?\n/)
        .map((line) => line.trim())
        .filter(Boolean)
        .slice(0, 6)
        .map((line) => truncateCells(line, width));
    return {
        title: agent.name,
        status: agent.scope,
        rows: [
            { label: "scope", value: agent.scope },
            { label: "model", value: agent.model || "inherit" },
            { label: "tools", value: summarizeAgentTools(agent.tools) },
            { label: "skills", value: summarizeAgentTools(agent.skills, 3) },
            { label: "path", value: agentPathLabel(agent.path, input.projectPath) },
            { label: "description", value: compactAgentDescription(agent.description, width) },
        ],
        promptPreview,
    };
}
export function AgentDetail(props) {
    if (!props.agent) {
        return (_jsx(Pane, { width: props.width, title: "Agent detail", tone: "muted", children: _jsx(Text, { color: "gray", children: "No agent selected" }) }));
    }
    const model = agentDetailModel({ agent: props.agent, projectPath: props.projectPath, width: props.width - 4 });
    return (_jsx(Pane, { width: props.width, title: model.title, tone: agentScopeTone(props.agent.scope), children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(StatusBadge, { label: model.status, tone: agentScopeTone(props.agent.scope) }) }), model.rows.map((row) => (_jsxs(Box, { children: [_jsx(Text, { color: "gray", children: row.label.padEnd(12) }), _jsx(Text, { children: truncateCells(row.value, Math.max(12, props.width - 16)) })] }, row.label))), model.promptPreview.length ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "gray", children: "prompt" }), model.promptPreview.map((line, index) => (_jsx(Text, { children: line }, `${index}:${line}`)))] })) : null] }) }));
}
