/** MessageInput -- Auto-resizing chat composer. Enter sends, Shift+Enter newlines. */ import { useState, useRef, useCallback } from 'react' interface MessageInputProps { onSend: (content: string) => void placeholder?: string } export function MessageInput({ onSend, placeholder = 'Type a message...' }: MessageInputProps) { const [value, setValue] = useState('') const textareaRef = useRef(null) const handleSend = useCallback(() => { const trimmed = value.trim() if (!trimmed) return onSend(trimmed) setValue('') if (textareaRef.current) { textareaRef.current.style.height = 'auto' } }, [value, onSend]) const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() handleSend() } } const handleInput = () => { const el = textareaRef.current if (!el) return el.style.height = 'auto' el.style.height = Math.min(el.scrollHeight, 160) + 'px' } return (