"use client" import { useState, ComponentType } from 'react' import FileUpload from './FileUpload' import { Box, Container, Typography, TextField, Button, CircularProgress, Paper, Fade, } from '@mui/material' import QuestionAnswerIcon from '@mui/icons-material/QuestionAnswer' import { motion } from 'framer-motion' interface Document { text: string } const MotionContainer = motion(Container as any) const MotionPaper = motion(Paper as any) export default function QASystem() { const [query, setQuery] = useState('') const [answer, setAnswer] = useState('') const [loading, setLoading] = useState(false) const [documents, setDocuments] = useState([]) const handleDocumentsLoaded = (newDocuments: Document[]) => { setDocuments(newDocuments) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (documents.length === 0) { alert('Please upload some documents first') return } setLoading(true) try { const response = await fetch('/api/qa', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ query, documents }), }) const data = await response.json() setAnswer(data.answer) } catch (error) { console.error('Error:', error) setAnswer('Failed to get answer. Please try again.') } finally { setLoading(false) } } return ( AI Document Assistant Upload your documents and get instant, AI-powered answers to your questions setQuery(e.target.value)} sx={{ mb: 3, '& .MuiOutlinedInput-root': { backgroundColor: 'white', borderRadius: 2, boxShadow: '0 2px 8px rgba(0, 0, 0, 0.05)', } }} variant="outlined" /> Answer {answer} ) }