import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { ConfigurableShortcutHint } from "./ConfigurableShortcutHint.js";
import { Byline } from "./design/Byline.js";
import { Divider } from "./design/Divider.js";
import { StatusBadge } from "./design/StatusBadge.js";
import { toneColor } from "./design/terminalTheme.js";
import { StatusNotices } from "./StatusNotices.js";
import { isChineseUi } from "../services/ui/languageService.js";
export function WelcomePanel(props) {
    const panelWidth = Math.max(44, Math.min(props.width - 2, 96));
    const detailWidth = Math.max(18, panelWidth - 38);
    const zh = isChineseUi(props.language);
    const rows = welcomeActionRows(props.providerReady, props.language);
    return (_jsxs(Box, { flexDirection: "column", paddingTop: 1, width: props.width, children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: toneColor("brand"), bold: true, children: zh ? "欢迎使用 DeepSeekCode" : "Welcome to DeepSeekCode" }), _jsx(Text, { children: " " }), _jsx(StatusBadge, { label: props.providerReady ? (zh ? "就绪" : "ready") : (zh ? "provider 缺失" : "provider missing"), tone: props.providerReady ? "success" : "warning" })] }), _jsx(Text, { color: "gray", children: `${zh ? "项目" : "project"} ${compactWelcomePath(props.projectPath, Math.max(20, panelWidth - 8))}` }), _jsx(Text, { color: "gray", children: formatWelcomeRuntimeStatus({
                    model: props.model,
                    permissionProfile: props.permissionProfile,
                    shellEnabled: props.shellEnabled,
                    browserEnabled: props.browserEnabled,
                    language: props.language,
                }) }), _jsx(StatusNotices, { providerReady: props.providerReady, permissionProfile: props.permissionProfile, shellEnabled: props.shellEnabled, browserEnabled: props.browserEnabled, width: panelWidth }), _jsx(Divider, { width: panelWidth, tone: "muted" }), _jsx(Box, { flexDirection: "column", children: rows.map((row) => (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: "gray", children: padRight(row.group, 10) }), _jsx(Text, { color: toneColor("brand"), children: padRight(row.command, 24) }), _jsx(Text, { color: "gray", children: truncate(row.detail, detailWidth) })] }, `${row.group}-${row.command}`))) }), _jsx(Divider, { width: panelWidth, tone: "muted" }), props.providerReady ? (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: "gray", children: zh ? "可用 " : "Use " }), _jsxs(Byline, { children: [_jsx(ConfigurableShortcutHint, { action: "prompt:fileMention", fallback: "@file", description: zh ? "添加上下文" : "attach context" }), _jsx(ConfigurableShortcutHint, { action: "app:commandPalette", fallback: "Ctrl+P", description: zh ? "命令" : "commands" }), _jsx(ConfigurableShortcutHint, { action: "app:quickOpen", fallback: "Ctrl+O", description: zh ? "快速打开" : "quick open" })] })] })) : (_jsx(Text, { color: "yellow", children: zh ? "请在 .env 设置 DEEPSEEK_API_KEY，然后运行 /doctor。" : "Set DEEPSEEK_API_KEY in .env, then run /doctor." }))] }));
}
export function welcomeActionRows(providerReady, language) {
    const zh = isChineseUi(language);
    const setupRow = providerReady
        ? { group: zh ? "状态" : "status", command: "/status", detail: zh ? "provider、git、缓存、权限" : "provider, git, cache, gates" }
        : { group: zh ? "配置" : "setup", command: "/doctor", detail: zh ? "检查 provider 和本地配置" : "check provider and local config" };
    return [
        setupRow,
        { group: zh ? "任务" : "ask", command: zh ? "输入任务" : "type a task", detail: zh ? "规划、编辑、审查或解释代码" : "plan, edit, review, or explain code" },
        { group: zh ? "文件" : "files", command: "Ctrl+O / @file", detail: zh ? "快速打开并添加项目上下文" : "quick open and attach project context" },
        { group: zh ? "命令" : "commands", command: "Ctrl+P / /help", detail: zh ? "浏览命令" : "browse command surface" },
        { group: zh ? "缓存" : "cache", command: "/cache plan <goal>", detail: zh ? "先预览稳定 prompt 块" : "preview stable prompt blocks first" },
        { group: zh ? "权限" : "safety", command: "/permissions", detail: zh ? "切换 shell/browser 权限" : "switch shell/browser profile" },
    ];
}
export function formatWelcomeRuntimeStatus(props) {
    const zh = isChineseUi(props.language);
    return [
        `model ${props.model}`,
        `${zh ? "权限" : "profile"} ${props.permissionProfile}`,
        `shell ${props.shellEnabled ? (zh ? "开" : "on") : (zh ? "关" : "off")}`,
        `browser ${props.browserEnabled ? (zh ? "开" : "on") : (zh ? "关" : "off")}`,
    ].join("  ");
}
export function compactWelcomePath(value, maxLength) {
    const normalized = value.trim();
    if (!normalized)
        return ".";
    const max = Math.max(8, maxLength);
    if (normalized.length <= max)
        return normalized;
    const keep = Math.max(4, max - 3);
    return `...${normalized.slice(normalized.length - keep)}`;
}
function padRight(value, width) {
    if (value.length >= width)
        return value.slice(0, width);
    return value + " ".repeat(width - value.length);
}
function truncate(value, width) {
    if (value.length <= width)
        return value;
    if (width <= 3)
        return value.slice(0, width);
    return `${value.slice(0, width - 3)}...`;
}
