import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { ChevronRight, AlertCircle } from 'lucide-react';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { prism, vscDarkPlus, } from 'react-syntax-highlighter/dist/esm/styles/prism';
import { formatDuration } from './utils';
import { ToolErrorDisplay } from './ToolErrorDisplay';
export function GenericRenderer({ toolName, contentJson, toolDurationMs, isExpanded, onToggle, compact, }) {
    const result = contentJson.result;
    const timeStr = formatDuration(toolDurationMs);
    const hasResult = result && Object.keys(result).length > 0;
    const syntaxTheme = document?.documentElement.classList.contains('dark')
        ? vscDarkPlus
        : prism;
    // Check for errors
    const hasError = contentJson.error ||
        (result &&
            typeof result === 'object' &&
            'ok' in result &&
            result.ok === false);
    const errorMessage = typeof contentJson.error === 'string'
        ? contentJson.error
        : result &&
            typeof result === 'object' &&
            'error' in result &&
            typeof result.error === 'string'
            ? result.error
            : null;
    const errorStack = result &&
        typeof result === 'object' &&
        'stack' in result &&
        typeof result.stack === 'string'
        ? result.stack
        : undefined;
    return (_jsxs("div", { className: "text-xs", children: [_jsxs("button", { type: "button", onClick: onToggle, className: `flex items-center gap-2 transition-colors w-full ${hasError
                    ? 'text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200'
                    : 'text-foreground hover:text-foreground/80'}`, children: [_jsx(ChevronRight, { className: `h-3 w-3 flex-shrink-0 transition-transform ${isExpanded ? 'rotate-90' : ''}` }), hasError && (_jsx(AlertCircle, { className: "h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400" })), _jsxs("span", { className: "font-medium flex-shrink-0", children: [toolName, hasError ? ' error' : ''] }), !compact && (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-muted-foreground/70 flex-shrink-0", children: "\u00B7" }), _jsx("span", { className: "text-muted-foreground/80 flex-shrink-0", children: timeStr })] }))] }), isExpanded && hasError && errorMessage && (_jsx(ToolErrorDisplay, { error: errorMessage, stack: errorStack, showStack: true })), isExpanded && !hasError && hasResult && (_jsx("div", { className: "mt-2 ml-5 bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 overflow-y-auto max-w-full", children: _jsx("div", { className: "overflow-x-auto max-w-full", children: _jsx(SyntaxHighlighter, { language: "json", style: syntaxTheme, customStyle: {
                            margin: 0,
                            padding: '0.75rem',
                            fontSize: '0.75rem',
                            lineHeight: '1.5',
                            background: 'transparent',
                            maxWidth: '100%',
                        }, wrapLines: true, wrapLongLines: true, children: JSON.stringify(result, null, 2) }) }) }))] }));
}
//# sourceMappingURL=GenericRenderer.js.map