import { useThemeColor } from '@/hooks/useThemeColor'; import { BrainCircuit, ChevronDown, ChevronRight } from 'lucide-react-native'; import React, { useEffect, useState } from 'react'; import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated'; interface ThinkingBlockProps { content: string; isComplete: boolean; isStreaming?: boolean; } export function ThinkingBlock({ content, isComplete, isStreaming }: ThinkingBlockProps) { const colors = useThemeColor(); // Auto-expand while streaming/thinking, auto-collapse when complete const [isExpanded, setIsExpanded] = useState(!isComplete); // Auto collapse when it completes streaming useEffect(() => { if (isComplete && !isStreaming) { setIsExpanded(false); } else if (!isComplete && isStreaming) { setIsExpanded(true); } }, [isComplete, isStreaming]); // Pulse animation value const pulseOpacity = useSharedValue(1); useEffect(() => { if (!isComplete && isStreaming) { pulseOpacity.value = withRepeat( withSequence( withTiming(0.4, { duration: 800 }), withTiming(1, { duration: 800 }) ), -1, // infinite true // reverse ); } else { pulseOpacity.value = withTiming(1, { duration: 300 }); } }, [isComplete, isStreaming, pulseOpacity]); const animatedHeaderStyle = useAnimatedStyle(() => { return { opacity: pulseOpacity.value, }; }); if (!content && isComplete) { return null; } return ( setIsExpanded(!isExpanded)} > {!isComplete && isStreaming ? 'Pensando...' : 'Processo de RaciocĂ­nio'} {isExpanded ? ( ) : ( )} {isExpanded && content.length > 0 && ( {content} )} ); } const styles = StyleSheet.create({ container: { borderWidth: 1, borderRadius: 8, marginVertical: 8, overflow: 'hidden', width: '100%', }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 12, paddingVertical: 10, }, titleRow: { flexDirection: 'row', alignItems: 'center', gap: 8, }, titleText: { fontSize: 13, fontWeight: '600', }, contentBlock: { paddingHorizontal: 12, paddingVertical: 10, borderTopWidth: 1, }, contentText: { fontSize: 14, lineHeight: 20, fontFamily: 'monospace', }, });