import React, { useState, useRef } from 'react'; import type { KeyboardEvent, DragEvent } from 'react'; import { Send, Paperclip, Mic, FileText, Image as ImageIcon, Sparkles, StopCircle, UploadCloud } from 'lucide-react'; interface ChatInputProps { onSendMessage: (text: string, attachments?: any[]) => void; isGenerating: boolean; onStopGeneration?: () => void; } export const ChatInput: React.FC = ({ onSendMessage, isGenerating, onStopGeneration }) => { const [text, setText] = useState(''); const [showAttachMenu, setShowAttachMenu] = useState(false); const [isDragging, setIsDragging] = useState(false); const [attachments, setAttachments] = useState<{ name: string; size: string; type: string }[]>([]); const textareaRef = useRef(null); const handleSend = () => { if ((!text.trim() && attachments.length === 0) || isGenerating) return; onSendMessage(text.trim(), attachments); setText(''); setAttachments([]); if (textareaRef.current) { textareaRef.current.style.height = 'auto'; } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleTextChange = (e: React.ChangeEvent) => { setText(e.target.value); if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 160)}px`; } }; const handleDragOver = (e: DragEvent) => { e.preventDefault(); setIsDragging(true); }; const handleDragLeave = () => { setIsDragging(false); }; const handleDrop = (e: DragEvent) => { e.preventDefault(); setIsDragging(false); if (e.dataTransfer.files && e.dataTransfer.files.length > 0) { const droppedFile = e.dataTransfer.files[0]; setAttachments([...attachments, { name: droppedFile.name, size: `${(droppedFile.size / 1024).toFixed(1)} KB`, type: droppedFile.type.includes('pdf') ? 'pdf' : 'image' }]); } }; const handleAttachFile = (type: string) => { const fakeFile = { name: type === 'pdf' ? 'Legal_Affidavit_Draft.pdf' : 'Document_Scan.png', size: type === 'pdf' ? '240 KB' : '1.2 MB', type }; setAttachments([...attachments, fakeFile]); setShowAttachMenu(false); }; // Estimate tokens (~4 chars per token) const tokenEstimate = Math.ceil(text.length / 4); return (
{/* Drag and Drop File Overlay */} {isDragging && (
Drop files here to attach to LawSLM
)} {/* Attached Files Preview Bar */} {attachments.length > 0 && (
{attachments.map((att, idx) => (
{att.name} ({att.size})
))}
)}
{/* Text Input Area */}