import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useRef, useEffect } from 'react';
import { ChevronDown, ChevronRight } from 'lucide-react';
export function ReasoningRenderer({ part }) {
    const [isExpanded, setIsExpanded] = useState(true);
    const scrollRef = useRef(null);
    const isHoveredRef = useRef(false);
    let content = '';
    const data = part.contentJson || part.content;
    if (data && typeof data === 'object' && 'text' in data) {
        content = String(data.text);
    }
    else if (typeof data === 'string') {
        content = data;
    }
    // biome-ignore lint/correctness/useExhaustiveDependencies: content dependency is intentional - triggers auto-scroll when new reasoning text streams in
    useEffect(() => {
        if (scrollRef.current &&
            isExpanded &&
            !part.completedAt &&
            !isHoveredRef.current) {
            scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
        }
    }, [content, isExpanded, part.completedAt]);
    if (!content || !content.trim()) {
        return null;
    }
    return (_jsxs("div", { className: "w-full", children: [_jsxs("button", { type: "button", onClick: () => setIsExpanded(!isExpanded), className: "flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors w-full", children: [isExpanded ? (_jsx(ChevronDown, { className: "h-3 w-3 flex-shrink-0" })) : (_jsx(ChevronRight, { className: "h-3 w-3 flex-shrink-0" })), _jsx("span", { className: "font-medium", children: "Reasoning" }), !part.completedAt && (_jsx("span", { className: "text-muted-foreground/60 animate-pulse", children: "thinking..." }))] }), isExpanded && (_jsx("div", { ref: scrollRef, className: "mt-2 p-3 bg-muted/30 rounded-md border border-border max-h-48 overflow-y-auto", role: "log", onMouseEnter: () => {
                    isHoveredRef.current = true;
                }, onMouseLeave: () => {
                    isHoveredRef.current = false;
                }, children: _jsx("div", { className: "text-sm text-muted-foreground whitespace-pre-wrap font-mono", children: content }) }))] }));
}
//# sourceMappingURL=ReasoningRenderer.js.map