import React, { useState, useEffect } from 'react'; import { useWorkflowOperations } from '../../../../hooks/useWorkflows'; import { Prompt } from '../../../../hooks/usePrompts'; import FileAttachmentPopup from './FileAttachmentPopup'; interface InputAreaProps { selectedPrompt?: Prompt | null; onPromptUsed?: () => void; onWorkflowIdChange?: (workflowId: string | null) => void; onAttachedFilesChange?: (files: AttachedFile[]) => void; attachedFiles?: AttachedFile[]; } interface AttachedFile { id: number; name: string; size: number; type: string; fileData?: File; objectUrl?: string; } const InputArea: React.FC = ({ selectedPrompt, onPromptUsed, onWorkflowIdChange, onAttachedFilesChange, attachedFiles: externalAttachedFiles = [] }) => { const [inputValue, setInputValue] = useState(''); const [showFilePopup, setShowFilePopup] = useState(false); // Always use external attached files from parent component const currentAttachedFiles = externalAttachedFiles; const { startWorkflow, startingWorkflow, startError } = useWorkflowOperations(); // Auto-fill input when prompt is selected useEffect(() => { if (selectedPrompt) { setInputValue(selectedPrompt.content); } }, [selectedPrompt]); const handleSend = async () => { if (!inputValue.trim() || startingWorkflow) return; try { const result = await startWorkflow({ prompt: inputValue, listFileId: currentAttachedFiles.map(f => f.id) }); if (result.success) { setInputValue(''); if (onAttachedFilesChange) { onAttachedFilesChange([]); } if (onPromptUsed) onPromptUsed(); if (onWorkflowIdChange && result.data?.id) { onWorkflowIdChange(result.data.id); } } } catch (error) { console.error('Failed to start workflow:', error); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleFilesAttached = (files: AttachedFile[]) => { setShowFilePopup(false); if (onAttachedFilesChange) { onAttachedFilesChange(files); } }; const formatFileSize = (bytes: number): string => { if (bytes < 1024) return bytes + ' B'; if (bytes < 1024 * 1024) return Math.round(bytes / 1024) + ' KB'; return Math.round(bytes / (1024 * 1024)) + ' MB'; }; return (

Input

{startError && (
Error: {startError}
)} {/* Show attached files count */} {currentAttachedFiles.length > 0 && (
📎 {currentAttachedFiles.length} file{currentAttachedFiles.length !== 1 ? 's' : ''} attached
)}