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 { generateAgentMarkdown } from "./generateAgent.js";
import { validateAgentDraft } from "./validateAgent.js";
export function agentEditorModel(draft, width = 88) {
    const validation = validateAgentDraft(draft);
    const markdownPreview = generateAgentMarkdown(draft)
        .split(/\r?\n/)
        .slice(0, 12)
        .map((line) => truncateCells(line, width));
    return {
        title: draft.name.trim() || "New agent",
        rows: [
            { label: "description", value: draft.description.trim() || "No description" },
            { label: "model", value: draft.model.trim() || "inherit" },
            { label: "color", value: draft.color.trim() || "cyan" },
            { label: "tools", value: draft.tools.length ? draft.tools.join(", ") : "all tools" },
            { label: "max turns", value: String(draft.maxTurns || 1) },
        ],
        errors: validation.errors,
        warnings: validation.warnings,
        markdownPreview,
        ready: validation.ok,
    };
}
export function AgentEditor(props) {
    const model = agentEditorModel(props.draft, Math.max(16, props.width - 4));
    return (_jsx(Pane, { width: props.width, title: model.title, tone: model.ready ? "success" : "warning", children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(StatusBadge, { label: model.ready ? "ready" : "draft", tone: model.ready ? "success" : "warning" }) }), model.rows.map((row) => (_jsxs(Box, { children: [_jsx(Text, { color: "gray", children: row.label.padEnd(13) }), _jsx(Text, { children: truncateCells(row.value, Math.max(12, props.width - 17)) })] }, row.label))), model.errors.map((error) => (_jsxs(Text, { color: "red", children: ["error: ", error] }, `error:${error}`))), model.warnings.map((warning) => (_jsxs(Text, { color: "yellow", children: ["warning: ", warning] }, `warning:${warning}`))), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "gray", children: "markdown" }), model.markdownPreview.map((line, index) => (_jsx(Text, { children: line || " " }, `${index}:${line}`)))] })] }) }));
}
