import { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import Layout from "@/components/Layout"; import { Button } from "@/components/ui/button"; import { useAuth } from "@/contexts/AuthContext"; import { useArmTheme } from "@/contexts/ArmThemeContext"; import { supabase } from "@/lib/supabase"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import LoadingScreen from "@/components/LoadingScreen"; import { Lightbulb, FileText, Zap, Lock, ExternalLink, ArrowRight, AlertCircle, Send } from "lucide-react"; import { ResearchWidget } from "@/components/ResearchWidget"; const API_BASE = import.meta.env.VITE_API_BASE || ""; export default function LabsDashboard() { const navigate = useNavigate(); const { user, loading: authLoading } = useAuth(); const { theme } = useArmTheme(); const [activeTab, setActiveTab] = useState("overview"); const [researchTracks, setResearchTracks] = useState([]); const [bounties, setBounties] = useState([]); const [publications, setPublications] = useState([]); const [ipPortfolio, setIpPortfolio] = useState(null); const [loading, setLoading] = useState(true); const [isAdmin, setIsAdmin] = useState(false); useEffect(() => { if (!authLoading && user) { loadDashboardData(); } }, [user, authLoading]); const loadDashboardData = async () => { try { setLoading(true); const { data: { session } } = await supabase.auth.getSession(); const token = session?.access_token; if (!token) throw new Error("No auth token"); const tracksRes = await fetch(`${API_BASE}/api/labs/research-tracks`, { headers: { Authorization: `Bearer ${token}` }, }); if (tracksRes.ok) setResearchTracks(await tracksRes.json()); const bountiesRes = await fetch(`${API_BASE}/api/labs/bounties`, { headers: { Authorization: `Bearer ${token}` }, }); if (bountiesRes.ok) setBounties(await bountiesRes.json()); const pubRes = await fetch(`${API_BASE}/api/labs/publications`, { headers: { Authorization: `Bearer ${token}` }, }); if (pubRes.ok) setPublications(await pubRes.json()); const ipRes = await fetch(`${API_BASE}/api/labs/ip-portfolio`, { headers: { Authorization: `Bearer ${token}` }, }); if (ipRes.ok) { const data = await ipRes.json(); setIpPortfolio(data); setIsAdmin(data?.is_admin || false); } } catch (error) { console.error("Failed to load LABS data", error); } finally { setLoading(false); } }; if (authLoading || loading) { return ; } if (!user) { return (

Research LABS

Discover cutting-edge R&D

); } return (
{/* Header */}

Research LABS

R&D Workshop | Blueprint Technical

{/* Tabs */} Overview Tracks Bounties Publications {/* Overview Tab */}

Active Tracks

{researchTracks.length}

Available Bounties

{bounties.length}

Publications

{publications.length}

{/* Recent Publications */} {publications.length > 0 && ( Recent Publications {publications.slice(0, 3).map((pub: any) => (

{pub.title}

{new Date(pub.published_date).toLocaleDateString()}

))}
)} {/* Submit Research Proposal CTA */}

Have a Research Idea?

Submit your research proposal for the LABS pipeline

{/* Research Tracks Tab */} ({ id: t.id, title: t.title, description: t.description, status: t.status, progress: t.progress || 0, publications: t.publications || [], whitepaper_url: t.whitepaper_url, lead: t.lead?.full_name, }))} title="Active Research Tracks" description="Internal R&D projects" accentColor="amber" /> {/* Bounties Tab */} Research Bounties High-difficulty opportunities from NEXUS {bounties.length === 0 ? (

No bounties available

) : (
{bounties.map((bounty: any) => (

{bounty.title}

${bounty.reward?.toLocaleString()}

{bounty.description}

))}
)}
{/* Publications Tab */} Publication Pipeline Upcoming whitepapers and technical blog posts {publications.length === 0 ? (

No publications

) : ( )}
{/* IP Dashboard - Admin Only */} {isAdmin && ( IP Dashboard (Admin Only) {ipPortfolio ? (

Patents Filed

{ipPortfolio.patents_count || 0}

Trademarks

{ipPortfolio.trademarks_count || 0}

Trade Secrets

{ipPortfolio.trade_secrets_count || 0}

Copyrights

{ipPortfolio.copyrights_count || 0}

) : (

IP portfolio data not available

)}
)}
); }