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";
import { MemoryUpdateNotification } from "./MemoryUpdateNotification.js";
export function ProjectMemoryPanel(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: "memory", tone: "brand", paddingX: 1, children: [props.updated && (_jsx(MemoryUpdateNotification, { memoryPath: props.model.subtitle, projectPath: props.projectPath, width: width - 4 })), _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: `${props.model.lines.length}`, tone: props.model.lines.length > 0 ? "brand" : "muted" })] }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: props.model.lines.length === 0 ? (_jsx(Text, { color: "gray", children: "Project memory is empty" })) : props.model.lines.slice(-12).map((line, index) => (_jsx(Text, { color: "gray", children: truncateCells(line, Math.max(24, width - 4)) }, `${index}-${line}`))) }), _jsx(Text, { color: "gray", children: truncateCells(props.model.footer, Math.max(24, width - 4)) })] }) }));
}
export function projectMemoryPanelModel(memory, path) {
    const lines = memory
        .split(/\r?\n/)
        .map((line) => line.trim())
        .filter(Boolean);
    return {
        title: "Project memory",
        subtitle: path,
        lines,
        footer: "/memory add <text> | /memory path",
    };
}
