/**
 * TUI renderer for code execution tools (execute_code).
 *
 * Renders a styled header with an icon and optional Excel cell reference highlighting,
 * plus syntax-highlighted code in expanded mode.
 */
import { Text } from '../../../../tui/index.js';
import { highlightCode } from '../../../theme/theme.js';
import { formatNotation, parseExcelLocation } from './excel-range.js';
/** Render a code execution tool call — icon + description, with optional syntax-highlighted code body. */
export function renderCodeExecCall(args, expanded, theme, options) {
    const parsedArgs = args && typeof args === 'object'
        ? args
        : undefined;
    const desc = typeof parsedArgs?.description === 'string' ? parsedArgs.description : '';
    const code = typeof parsedArgs?.code === 'string' ? parsedArgs.code : '';
    let label = desc || options.emptyLabel;
    const loc = desc ? parseExcelLocation(desc) : null;
    if (loc) {
        const notation = formatNotation(loc);
        if (notation) {
            const styled = theme.fg('accent', notation);
            const bracketedIdx = label.indexOf(`<${notation}>`);
            if (bracketedIdx >= 0) {
                label = label.replace(`<${notation}>`, styled);
            }
            else {
                label = label.replace(notation, styled);
            }
        }
    }
    const title = theme.fg('toolTitle', theme.bold(`${options.collapsedIcon} ${label}`));
    if (!expanded) {
        return new Text(title, 0, 0);
    }
    if (!code) {
        return new Text(`${title}\n\n${theme.fg('toolOutput', '...')}`, 0, 0);
    }
    if (!options.language) {
        return new Text(`${title}\n\n${code}`, 0, 0);
    }
    const highlighted = highlightCode(code, options.language);
    return new Text(`${title}\n\n${highlighted.join('\n')}`, 0, 0);
}
//# sourceMappingURL=code-exec.js.map