import { useState, useRef } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { FileText, Upload, X, ChevronRight, ChevronLeft, Search, Trash2, FileUp, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ScrollArea } from "@/components/ui/scroll-area"; import { PDFDocument } from "@/types/chat"; import { cn } from "@/lib/utils"; interface PDFViewerProps { documents: PDFDocument[]; activeDocument: PDFDocument | null; isLoading: boolean; onUpload: (file: File) => Promise; onRemove: (id: string) => void; onSelect: (doc: PDFDocument) => void; } export function PDFViewer({ documents, activeDocument, isLoading, onUpload, onRemove, onSelect, }: PDFViewerProps) { const [isDragging, setIsDragging] = useState(false); const [search, setSearch] = useState(""); const fileInputRef = useRef(null); const handleDrop = async (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); const files = Array.from(e.dataTransfer.files).filter( (f) => f.type === "application/pdf" ); for (const file of files) { await onUpload(file); } }; const handleFileSelect = async (e: React.ChangeEvent) => { const files = Array.from(e.target.files || []); for (const file of files) { await onUpload(file); } if (fileInputRef.current) { fileInputRef.current.value = ""; } }; const filteredDocs = documents.filter((d) => d.name.toLowerCase().includes(search.toLowerCase()) ); return (
{/* Header */}

Documents

{documents.length > 0 && (
setSearch(e.target.value)} placeholder="Search documents..." className="pl-9 bg-input/50 border-border h-9" />
)}
{/* Content */}
{/* Drop Zone */}
{ e.preventDefault(); setIsDragging(true); }} onDragLeave={() => setIsDragging(false)} onDrop={handleDrop} className={cn( "border-2 border-dashed rounded-xl p-6 transition-colors text-center mb-4", isDragging ? "border-primary bg-primary/5" : "border-border hover:border-muted-foreground" )} >

{isDragging ? "Drop PDF here" : "Drag & drop PDF files here"}

or click Upload above

{/* Loading */} {isLoading && (
)} {/* Document List */}
{filteredDocs.map((doc) => ( onSelect(doc)} >

{doc.name}

{doc.pages} page{doc.pages !== 1 ? "s" : ""} •{" "} {new Date(doc.uploadedAt).toLocaleDateString()}

))}
{/* Empty State */} {documents.length === 0 && !isLoading && (

No documents yet

Upload PDFs to chat with them

)}
{/* Active Document Preview */} {activeDocument && (
{activeDocument.name}
Active for RAG
)}
); }