import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
export function CommandResultPanel({ expanded, results, }) {
    const visibleResults = results.filter(isHandledResult);
    if (visibleResults.length === 0) {
        return null;
    }
    if (!expanded) {
        return _jsx(CollapsedCommandResult, { result: visibleResults.at(-1) });
    }
    return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "green", children: "Command" }), _jsx(Text, { dimColor: true, children: " \u00B7 /c to collapse" })] }), visibleResults.map((result, index) => (_jsx(Box, { flexDirection: "column", marginTop: index === 0 ? 0 : 1, children: renderResult(result) }, index)))] }));
}
function CollapsedCommandResult({ result, }) {
    if (!result) {
        return null;
    }
    return (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { children: [_jsx(Text, { color: "green", children: "Command" }), _jsxs(Text, { dimColor: true, children: [" \u00B7 ", summarizeResult(result)] }), _jsx(Text, { dimColor: true, children: " \u00B7 /c to expand" })] }) }));
}
function renderResult(result) {
    if (result.kind === 'message') {
        return _jsx(Text, { children: result.message });
    }
    if (result.kind === 'continue') {
        return _jsx(Text, { children: result.message ?? 'Continuing session.' });
    }
    return _jsx(Text, { children: result.message ?? result.displayText });
}
function isHandledResult(result) {
    return result.handled;
}
function summarizeResult(result) {
    const text = result.kind === 'execute'
        ? (result.message ?? result.displayText)
        : result.message;
    const firstLine = text?.split(/\r?\n/, 1)[0]?.trim();
    if (!firstLine) {
        return result.kind === 'continue' ? 'continuing session' : result.kind;
    }
    return firstLine.length > 80 ? `${firstLine.slice(0, 77)}...` : firstLine;
}
//# sourceMappingURL=CommandResultPanel.js.map