import React, { useState, KeyboardEvent, useRef } from 'react'; import { Send, Loader2, Plus, X } from 'lucide-react'; interface ChatInputProps { onSend: (message: string) => void; disabled?: boolean; isLoading?: boolean; onImageSelect?: (image: string | null) => void; currentImage?: string | null; supportsImages?: boolean; } export const ChatInput: React.FC = ({ onSend, disabled = false, isLoading = false, onImageSelect, currentImage, supportsImages = false }) => { const [input, setInput] = useState(''); const [preview, setPreview] = useState(currentImage || null); const fileInputRef = useRef(null); const handleSend = () => { if (input.trim() && !disabled && !isLoading) { onSend(input.trim()); setInput(''); } }; const handleKeyPress = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onloadend = () => { const result = reader.result as string; setPreview(result); onImageSelect?.(result); }; reader.readAsDataURL(file); } }; const handleRemoveImage = () => { setPreview(null); onImageSelect?.(null); if (fileInputRef.current) { fileInputRef.current.value = ''; } }; // Update preview when currentImage changes React.useEffect(() => { setPreview(currentImage || null); }, [currentImage]); return (
{/* Image Preview */} {preview && (
Preview
)}
{/* Hidden File Input */} {/* Plus Button for Image Upload */}