'use client'; import * as React from 'react'; import { Brain, ChevronDown, Maximize2, Minimize2 } from 'lucide-react'; import { cn } from '@/lib/utils'; import Markdown from 'markdown-to-jsx'; import logger from '@/lib/logger'; interface ReasoningPanelProps { thinking: string; className?: string; isExpanded?: boolean; } const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: ReasoningPanelProps): React.ReactElement => { const [isExpanded, setIsExpanded] = React.useState(true); const [detailsRefs, setDetailsRefs] = React.useState([]); React.useEffect(() => { if (propExpanded !== undefined) { setIsExpanded(propExpanded); } }, [propExpanded]); const addDetailsRef = React.useCallback((element: HTMLDetailsElement | null) => { if (element) { setDetailsRefs(refs => { if (!refs.includes(element)) { return [...refs, element]; } return refs; }); } }, []); const expandAll = () => { detailsRefs.forEach(ref => ref.open = true); }; const collapseAll = () => { detailsRefs.forEach(ref => ref.open = false); }; return (
{isExpanded && (
{thinking.split('\n\n').map((paragraph, index) => { if (!paragraph.trim()) return null; const content = paragraph.replace(/^[•\-\d.]\s*/, ''); return (

{content}

{/* Content is shown in the summary when expanded - no need to render it again */}
); })}
)}
); }; export default ReasoningPanel;