import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import React from 'react';
import ToolMessage from '../components/tool-message.js';
import { ThemeContext } from '../hooks/useTheme.js';
/**
 * Build a formatter for the common tool-output shape: a `⚒ <tool_name>` header
 * followed by a column of `Label: value` rows, wrapped in a borderless
 * `ToolMessage`. Tools whose output needs richer rendering (syntax-highlighted
 * diffs, colour-coded stats, etc.) should keep their bespoke formatter.
 *
 * `getRows` is called with the tool args and (once available) its string
 * result, so the same definition covers both the pre- and post-execution
 * render.
 */
export function makeSimpleToolFormatter(toolName, getRows) {
    const Formatter = React.memo(({ args, result }) => {
        const themeContext = React.useContext(ThemeContext);
        if (!themeContext) {
            throw new Error('ThemeContext is required');
        }
        const { colors } = themeContext;
        const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: colors.tool, children: ["\u2692 ", toolName] }), getRows(args, result).map(row => row.value === undefined ? null : (_jsxs(Box, { children: [_jsxs(Text, { color: colors.secondary, children: [row.label, ": "] }), _jsx(Text, { wrap: "truncate-end", color: colors.text, children: typeof row.value === 'string' ? row.value : String(row.value) })] }, row.label)))] }));
        return _jsx(ToolMessage, { message: messageContent, hideBox: true });
    });
    return (args, result) => (_jsx(Formatter, { args: args, result: result }));
}
//# sourceMappingURL=simple-tool-formatter.js.map