import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { ChevronRight, AlertCircle } from 'lucide-react';
import { DiffView } from './DiffView';
import { formatDuration } from './utils';
import { ToolErrorDisplay } from './ToolErrorDisplay';
export function EditRenderer({ args, result, artifact, toolDurationMs, isExpanded, onToggle, }) {
    const hasToolError = typeof result === 'object' && 'ok' in result && result.ok === false;
    const errorMessage = hasToolError && 'error' in result && typeof result.error === 'string'
        ? result.error
        : null;
    const errorStack = hasToolError && 'stack' in result && typeof result.stack === 'string'
        ? result.stack
        : undefined;
    const path = String(result.path || args.path || '');
    const opsApplied = Number(result.opsApplied || 0);
    const patch = artifact?.patch ? String(artifact.patch) : '';
    const timeStr = formatDuration(toolDurationMs);
    const canExpand = patch.length > 0 || hasToolError;
    return (_jsxs("div", { className: "text-xs", children: [_jsxs("button", { type: "button", onClick: () => canExpand && onToggle(), className: `flex items-center gap-2 transition-colors min-w-0 w-full ${hasToolError
                    ? 'text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200'
                    : canExpand
                        ? 'text-purple-700 dark:text-purple-300 hover:text-purple-600 dark:hover:text-purple-200'
                        : 'text-purple-700 dark:text-purple-300'}`, children: [canExpand ? (isExpanded ? (_jsx(ChevronRight, { className: "h-3 w-3 flex-shrink-0 rotate-90 transition-transform" })) : (_jsx(ChevronRight, { className: "h-3 w-3 flex-shrink-0 transition-transform" }))) : (_jsx("div", { className: "w-3 flex-shrink-0" })), hasToolError && (_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: ["edit", hasToolError ? ' error' : ''] }), _jsx("span", { className: "text-muted-foreground/70 flex-shrink-0", children: "\u00B7" }), _jsx("span", { className: "text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap", dir: "rtl", title: path, children: path }), !hasToolError && opsApplied > 0 && (_jsxs("span", { className: "text-muted-foreground/80 whitespace-nowrap flex-shrink-0", children: ["\u00B7 ", opsApplied, " ops \u00B7 ", timeStr] })), hasToolError && (_jsxs("span", { className: "text-muted-foreground/80 flex-shrink-0", children: ["\u00B7 ", timeStr] }))] }), isExpanded && hasToolError && errorMessage && (_jsx(ToolErrorDisplay, { error: errorMessage, stack: errorStack, showStack: true })), isExpanded && !hasToolError && patch && (_jsx("div", { className: "mt-2 ml-5", children: _jsx(DiffView, { patch: patch }) }))] }));
}
//# sourceMappingURL=EditRenderer.js.map