import { useThemeColor } from '@/hooks/useThemeColor'; import * as Haptics from 'expo-haptics'; import { Send, Square, X } from 'lucide-react-native'; import React, { useEffect, useState } from 'react'; import { Platform, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'; interface ChatInputProps { onSend: (text: string) => void; onStop?: () => void; isLoading?: boolean; editingText?: string | null; onCancelEdit?: () => void; } export function ChatInput({ onSend, onStop, isLoading, editingText, onCancelEdit }: ChatInputProps) { const [text, setText] = useState(''); const colors = useThemeColor(); // When editingText changes, fill the input useEffect(() => { if (editingText !== null && editingText !== undefined) { setText(editingText); } }, [editingText]); const handleSend = () => { if (text.trim() && !isLoading) { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); onSend(text.trim()); setText(''); } }; const handleStop = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium); onStop?.(); }; const handleCancelEdit = () => { setText(''); onCancelEdit?.(); }; const handleKeyPress = (e: any) => { if (Platform.OS === 'web') { if (e.nativeEvent.key === 'Enter' && !e.nativeEvent.shiftKey) { e.preventDefault(); handleSend(); } } }; const isEditing = editingText !== null && editingText !== undefined; return ( {/* Edit mode banner */} {isEditing && ( Editing message )} {/* Send or Stop button */} {isLoading ? ( ) : ( )} ); } const styles = StyleSheet.create({ outerContainer: { borderTopWidth: 1, }, editBanner: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16, paddingVertical: 8, borderBottomWidth: 1, }, editBannerText: { fontSize: 13, fontWeight: '500', }, editCancelBtn: { padding: 4, }, container: { padding: 12, paddingBottom: Platform.OS === 'ios' ? 24 : 12, }, inputWrapper: { flexDirection: 'row', alignItems: 'flex-end', borderRadius: 24, paddingHorizontal: 16, paddingVertical: 6, minHeight: 44, maxHeight: 120, }, input: { flex: 1, fontSize: 15, lineHeight: 22, paddingTop: 8, paddingBottom: 8, }, sendButton: { width: 34, height: 34, borderRadius: 17, alignItems: 'center', justifyContent: 'center', marginLeft: 8, marginBottom: 2, }, stopButton: { width: 34, height: 34, borderRadius: 17, alignItems: 'center', justifyContent: 'center', marginLeft: 8, marginBottom: 2, }, });