"use client"; import { useMemo, useRef, useState } from "react"; import { AlertCircle, CheckCircle2, FileText, Loader2, Plus, Search, Trash2, UploadCloud, } from "lucide-react"; import { api } from "@/lib/api"; import { toast } from "@/lib/toast"; import type { DocumentMeta } from "@/lib/types"; function StatusDot({ status }: { status: DocumentMeta["status"] }) { if (status === "ready") return ; if (status === "failed") return ; return ; } function timeAgo(iso: string): string { const d = new Date(iso).getTime(); if (isNaN(d)) return ""; const s = Math.floor((Date.now() - d) / 1000); if (s < 60) return "just now"; if (s < 3600) return `${Math.floor(s / 60)}m ago`; if (s < 86400) return `${Math.floor(s / 3600)}h ago`; return `${Math.floor(s / 86400)}d ago`; } export default function Sidebar({ docs, activeId, onSelect, onUploaded, onDeleted, }: { docs: DocumentMeta[]; activeId: string | null; onSelect: (id: string) => void; onUploaded: (meta: DocumentMeta) => void; onDeleted: (id: string) => void; }) { const inputRef = useRef(null); const [uploading, setUploading] = useState(false); const [drag, setDrag] = useState(false); const [q, setQ] = useState(""); const filtered = useMemo( () => docs.filter((d) => d.filename.toLowerCase().includes(q.toLowerCase())), [docs, q], ); const doUpload = async (file: File) => { setUploading(true); const t = toast.info("Uploading…", file.name); try { const meta = await api.upload(file); onUploaded(meta); toast.success("Uploaded", `${file.name} is being processed.`); } catch (e: any) { toast.error("Upload failed", e?.message ?? String(e)); } finally { setUploading(false); } }; return ( ); }