/** * Chat Input Component * Textarea with send button. Enter to send, Shift+Enter for new line. */ import { useState, useRef, useEffect, useCallback } from 'react'; import { Send, Square } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; interface ChatInputProps { onSend: (text: string) => void; disabled?: boolean; sending?: boolean; } export function ChatInput({ onSend, disabled = false, sending = false }: ChatInputProps) { const [input, setInput] = useState(''); const textareaRef = useRef(null); // Auto-resize textarea useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 200)}px`; } }, [input]); const handleSend = useCallback(() => { const trimmed = input.trim(); if (!trimmed || disabled || sending) return; onSend(trimmed); setInput(''); // Reset textarea height if (textareaRef.current) { textareaRef.current.style.height = 'auto'; } }, [input, disabled, sending, onSend]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }, [handleSend], ); return (