"use client"; import { useEffect, useRef, useState } from "react"; import { ChevronDown } from "lucide-react"; export function PreResponseWrapper({ children, stepCount, shouldMinimize, isStreaming, compact = false, }: { children: React.ReactNode; stepCount: number; shouldMinimize: boolean; isStreaming: boolean; /** Tighter typography + child gap for narrow side panels (e.g. TR chat). */ compact?: boolean; }) { const [userToggled, setUserToggled] = useState(false); const [isOpen, setIsOpen] = useState(!shouldMinimize); // Once content has streamed in (shouldMinimize=true even once), stay // minimized even if a later render briefly evaluates shouldMinimize=false. // Without this latch, the wrapper visibly pops open when isStreaming // flips off at the end of the response. const hasMinimizedRef = useRef(shouldMinimize); useEffect(() => { if (shouldMinimize) hasMinimizedRef.current = true; if (userToggled) return; setIsOpen(!shouldMinimize && !hasMinimizedRef.current); }, [shouldMinimize, userToggled]); const stepWord = `step${stepCount === 1 ? "" : "s"}`; const label = isStreaming ? "Working" : `Completed in ${stepCount} ${stepWord}`; const buttonTextClass = compact ? "text-xs" : "text-sm"; const childrenGapClass = compact ? "gap-2.5" : "gap-4"; return (