import { useState, useEffect } from "react"; import { FileText, Database, Activity, TrendingUp, AlertCircle, CheckCircle, Loader2, } from "lucide-react"; import { api } from "@/services/api"; interface DashboardTabProps { selectedTema: string | null; } interface DataroomInfo { name: string; collection: string; storage: string; file_count: number; total_size_bytes: number; total_size_mb: number; collection_exists: boolean; vector_count: number | null; collection_info: { vectors_count: number; indexed_vectors_count: number; points_count: number; segments_count: number; status: string; } | null; file_types: Record; recent_files: Array<{ name: string; size_mb: number; last_modified: string; }>; } export function DashboardTab({ selectedTema }: DashboardTabProps) { const [dataroomInfo, setDataroomInfo] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (selectedTema) { fetchDataroomInfo(); } }, [selectedTema]); const fetchDataroomInfo = async () => { if (!selectedTema) return; setLoading(true); setError(null); try { const info = await api.getDataroomInfo(selectedTema); setDataroomInfo(info); } catch (err) { const errorMessage = err instanceof Error ? err.message : "Unknown error"; setError(`Unable to load dataroom info: ${errorMessage}`); console.error("Error fetching dataroom info:", err); } finally { setLoading(false); } }; const formatFileTypes = (fileTypes: Record) => { const entries = Object.entries(fileTypes); if (entries.length === 0) return "No files"; return entries .sort(([, a], [, b]) => b - a) // Sort by count descending .slice(0, 3) // Take top 3 .map(([ext, count]) => `${ext.toUpperCase()}: ${count}`) .join(", "); }; const formatBytes = (bytes: number) => { if (bytes === 0) return "0 MB"; const mb = bytes / (1024 * 1024); if (mb < 1) return `${(bytes / 1024).toFixed(1)} KB`; return `${mb.toFixed(1)} MB`; }; if (!selectedTema) { return (

Select a dataroom to view its metrics

); } if (loading) { return (

Loading metrics…

); } if (error) { return (

Error

{error}

); } if (!dataroomInfo) { return (

Unable to load dataroom information

); } return (

Metrics

{/* Files Count Card */}

Files

{dataroomInfo.file_count}

{formatFileTypes(dataroomInfo.file_types)}

{/* Storage Usage Card */}

Storage

{dataroomInfo.total_size_mb.toFixed(1)} MB

{formatBytes(dataroomInfo.total_size_bytes)}

{/* Vector Collections Card */}

Vectors

{dataroomInfo.vector_count ?? 0}

{dataroomInfo.collection_exists ? "Indexed vectors" : "No vectors"}

{/* Collection Status Card */}

Status

{dataroomInfo.collection_exists ? "Active" : "Inactive"}

{dataroomInfo.collection_exists ? ( ) : ( )}
{dataroomInfo.collection_info ? (

{dataroomInfo.collection_info.indexed_vectors_count}/ {dataroomInfo.collection_info.vectors_count} indexed vectors

) : (

{dataroomInfo.collection_exists ? "Collection has no data" : "No collection"}

)}
{/* Recent Files Section */} {dataroomInfo.recent_files.length > 0 && (

Recent Files

{dataroomInfo.recent_files.map((file, index) => (

{file.name}

{new Date(file.last_modified).toLocaleDateString( "en-US", { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }, )}

{file.size_mb.toFixed(2)} MB

))}
)}
); }