import React from 'react'; import { ClientOnly } from 'remix-utils/client-only'; import { IconButton } from '~/components/ui/IconButton'; import { classNames } from '~/utils/classNames'; import { SendButton } from '~/components/chat/SendButton.client'; import { SpeechRecognitionButton } from '~/components/chat/SpeechRecognition'; export interface MessageInputProps { textareaRef?: React.RefObject; input?: string; handleInputChange?: (event: React.ChangeEvent) => void; handleSendMessage?: (event: React.UIEvent) => void; handleStop?: () => void; hasPendingMessage?: boolean; chatStarted?: boolean; uploadedFiles?: File[]; setUploadedFiles?: (files: File[]) => void; imageDataList?: string[]; setImageDataList?: (dataList: string[]) => void; isListening?: boolean; onStartListening?: () => void; onStopListening?: () => void; minHeight?: number; maxHeight?: number; } export const MessageInput: React.FC = ({ textareaRef, input = '', handleInputChange = () => {}, handleSendMessage = () => {}, handleStop = () => {}, hasPendingMessage = false, chatStarted = false, uploadedFiles = [], setUploadedFiles = () => {}, imageDataList = [], setImageDataList = () => {}, isListening = false, onStartListening = () => {}, onStopListening = () => {}, minHeight = 76, maxHeight = 200, }) => { const handleFileUpload = () => { const input = document.createElement('input'); input.type = 'file'; input.accept = 'image/*'; input.onchange = async (e) => { const file = (e.target as HTMLInputElement).files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { const base64Image = e.target?.result as string; setUploadedFiles([...uploadedFiles, file]); setImageDataList([...imageDataList, base64Image]); }; reader.readAsDataURL(file); } }; input.click(); }; const handlePaste = async (e: React.ClipboardEvent) => { const items = e.clipboardData?.items; if (!items) { return; } for (const item of items) { if (item.type.startsWith('image/')) { e.preventDefault(); const file = item.getAsFile(); if (file) { const reader = new FileReader(); reader.onload = (e) => { const base64Image = e.target?.result as string; setUploadedFiles([...uploadedFiles, file]); setImageDataList([...imageDataList, base64Image]); }; reader.readAsDataURL(file); } break; } } }; return (