import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { useTerminalSize } from "../hooks/useTerminalSize.js";
import { Pane } from "./design/Pane.js";
import { StatusBadge } from "./design/StatusBadge.js";
import { truncateCells } from "./design/textLayout.js";
export function ConfigPanel(props) {
    const { columns } = useTerminalSize();
    const width = Math.max(52, Math.min(112, columns - 4));
    return (_jsx(Box, { flexDirection: "column", marginBottom: 1, children: _jsxs(Pane, { width: width, title: "config", tone: "brand", paddingX: 1, children: [_jsxs(Box, { flexDirection: "row", justifyContent: "space-between", children: [_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: "cyan", children: props.model.title }), _jsx(Text, { color: "gray", children: truncateCells(props.model.subtitle, Math.max(24, width - 20)) })] }), _jsx(StatusBadge, { label: "redacted", tone: "muted" })] }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: props.model.rows.map((row) => (_jsx(ConfigPanelRowView, { row: row, width: width }, row.key))) }), _jsx(Text, { color: "gray", children: truncateCells(props.model.footer, Math.max(24, width - 4)) })] }) }));
}
export function configPanelModel(input) {
    const provider = input.config.provider;
    const rows = [
        {
            key: "provider",
            label: "provider",
            status: provider ? "ready" : "missing",
            tone: provider ? "success" : "warning",
            value: provider
                ? `${provider.name} ${provider.kind} ${provider.model}`
                : "DEEPSEEK_API_KEY not configured",
            note: provider ? `${provider.baseUrl} apiKey=[redacted]` : "set DEEPSEEK_API_KEY in .env or provider profile",
        },
        {
            key: "model",
            label: "model",
            status: "active",
            tone: "brand",
            value: input.config.model,
            note: provider?.reasoningEffort ? `reasoning=${provider.reasoningEffort}` : "",
        },
        {
            key: "project",
            label: "project",
            status: "path",
            tone: "muted",
            value: input.config.projectPath,
            note: `state=${input.config.stateDbPath}`,
        },
        {
            key: "data",
            label: "data",
            status: "path",
            tone: "muted",
            value: input.config.dataDir,
            note: "runtime state and transcripts",
        },
        {
            key: "style",
            label: "style",
            status: input.outputStyle.scope,
            tone: input.outputStyle.scope === "builtin" ? "brand" : "success",
            value: input.outputStyle.name,
            note: input.outputStyle.description,
        },
        {
            key: "inference",
            label: "effort",
            status: input.inference.effort,
            tone: input.inference.effort === "max" ? "warning" : "brand",
            value: `action=${input.inference.actionContextChars}/${input.inference.actionDynamicChars}`,
            note: `side=${input.inference.sideQuestionContextChars}/${input.inference.sideQuestionDynamicChars} maxOutput=${input.inference.maxOutputTokens}`,
        },
        {
            key: "permissions",
            label: "perm",
            status: input.permissions.profile ?? input.config.permissionProfile,
            tone: input.permissions.allowShell || input.permissions.allowBrowser ? "warning" : "success",
            value: `shell=${input.permissions.allowShell ? "on" : "off"} browser=${input.permissions.allowBrowser ? "on" : "off"}`,
            note: "/permissions profile safe|dev|browser|open",
        },
    ];
    return {
        title: "DeepSeekCode runtime config",
        subtitle: "safe read-only view; secrets are never printed",
        rows,
        footer: "/config shows runtime settings; /doctor verifies native tool calling and integrations",
    };
}
function ConfigPanelRowView(props) {
    const valueWidth = Math.max(20, props.width - 36);
    const noteWidth = Math.max(20, props.width - 12);
    return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(StatusBadge, { label: props.row.status, tone: props.row.tone }), _jsx(Text, { children: " " }), _jsx(Text, { color: "cyan", children: truncateCells(props.row.label.padEnd(9), 9) }), _jsx(Text, { color: "gray", children: truncateCells(props.row.value, valueWidth) })] }), props.row.note ? (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: "gray", children: "  " }), _jsx(Text, { color: "gray", children: truncateCells(props.row.note, noteWidth) })] })) : null] }));
}
