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, Briefcase, TrendingUp, Code2, } from "lucide-react"; const API_BASE = import.meta.env.VITE_API_BASE || ""; interface ResearchTrack { id: string; title: string; description: string; status: "scoping" | "research" | "in-development" | "testing" | "released"; progress: number; lead_name: string; team_size: number; } interface IPPortfolioItem { id: string; name: string; type: "patent" | "trademark" | "trade-secret" | "copyright"; status: "filed" | "pending" | "secured" | "expired"; filing_date: string; licensed_to: string; } interface Publication { id: string; title: string; description: string; status: "drafting" | "review" | "published"; author: string; published_date: string; url?: string; } interface ResearchBounty { id: string; title: string; description: string; reward: number; difficulty: "intermediate" | "advanced" | "expert"; applicants_count: number; } export default function LabsDashboard() { const navigate = useNavigate(); const { user, loading: authLoading } = useAuth(); const { theme } = useArmTheme(); const [activeTab, setActiveTab] = useState("overview"); const [isAccessible, setIsAccessible] = useState(false); const [researchTracks, setResearchTracks] = useState([]); const [ipPortfolio, setIpPortfolio] = useState([]); const [publications, setPublications] = useState([]); const [bounties, setBounties] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { if (!authLoading && user) { checkAccessAndLoadData(); } else if (!authLoading && !user) { setLoading(false); } }, [user, authLoading]); const checkAccessAndLoadData = async () => { try { setLoading(true); // Check if user has labs affiliation const { data: { session }, } = await supabase.auth.getSession(); const token = session?.access_token; if (!token) throw new Error("No auth token"); // Check arm affiliations const affiliationRes = await fetch( `${API_BASE}/api/user/arm-affiliations`, { headers: { Authorization: `Bearer ${token}` }, }, ); let hasLabsAccess = false; if (affiliationRes.ok) { const data = await affiliationRes.json(); hasLabsAccess = data.arms?.includes("labs") || data.role === "admin" || data.verified; } setIsAccessible(hasLabsAccess); if (hasLabsAccess) { // Load research tracks try { const tracksRes = await fetch( `${API_BASE}/api/labs/research-tracks`, { headers: { Authorization: `Bearer ${token}` }, }, ); if (tracksRes.ok) { const data = await tracksRes.json(); setResearchTracks(Array.isArray(data) ? data : []); } } catch { // Silently ignore } // Load IP portfolio try { const ipRes = await fetch(`${API_BASE}/api/labs/ip-portfolio`, { headers: { Authorization: `Bearer ${token}` }, }); if (ipRes.ok) { const data = await ipRes.json(); setIpPortfolio(Array.isArray(data) ? data : []); } } catch { // Silently ignore } // Load publications (all) try { const pubRes = await fetch(`${API_BASE}/api/labs/publications`, { headers: { Authorization: `Bearer ${token}` }, }); if (pubRes.ok) { const data = await pubRes.json(); setPublications(Array.isArray(data) ? data : []); } } catch { // Silently ignore } // Load bounties try { const bountiesRes = await fetch(`${API_BASE}/api/labs/bounties`, { headers: { Authorization: `Bearer ${token}` }, }); if (bountiesRes.ok) { const data = await bountiesRes.json(); setBounties(Array.isArray(data) ? data : []); } } catch { // Silently ignore } } } catch { // Silently ignore errors } finally { setLoading(false); } }; if (authLoading || loading) { return ; } if (!user) { return (

AeThex LABS

Our proprietary R&D skunkworks

Access our cutting-edge research, IP portfolio, and publications

); } if (!isAccessible) { return (

Join LABS?

LABS is our internal R&D department for A-Corp employees

What is LABS?

LABS is our proprietary, for-profit R&D department that takes the open-source Axiom Protocol and builds competitive, closed-source "secret weapons" on top of it.

We house active research tracks, manage our IP portfolio, publish technical whitepapers, and post high-difficulty research bounties to our elite architect community.

To join LABS, you must be a verified A-Corp employee or architect with proven expertise

); } // Main dashboard - user has access return (
{/* Header */}

LABS

R&D Workshop | Proprietary Research & IP Management

{/* Tabs */} Overview Research Tracks Publications Bounties {/* Overview Tab */} {/* Quick Stats */}

Active Tracks

{researchTracks.length}

IP Assets

{ipPortfolio.length}

Publications

{publications.length}

Bounties

{bounties.length}

{/* Featured Research Track */} {researchTracks.length > 0 && ( Featured Research Track Our current flagship R&D initiative {(() => { const featured = researchTracks[0]; return (

{featured.title}

{featured.description}

Lead

{featured.lead_name}

Team Size

{featured.team_size} members

Progress

{featured.progress}%

Overall Progress {featured.progress}%
{featured.status.replace("-", " ")}
); })()} )} {/* Recent Publications */} {publications.filter((p) => p.status === "published").length > 0 && ( Recent Publications Latest technical whitepapers and blog posts {publications .filter((p) => p.status === "published") .slice(0, 3) .map((pub) => (

{pub.title}

By {pub.author} •{" "} {new Date( pub.published_date, ).toLocaleDateString()}

))}
)} {/* CTA Section */}

Submit Research Proposal

Propose a new R&D initiative for LABS

Browse LABS Bounties

High-difficulty research opportunities from NEXUS

{/* Research Tracks Tab */} {researchTracks.length === 0 ? (

No active research tracks

) : (
{researchTracks.map((track) => (
{track.title}
{track.status.replace("-", " ")}

{track.description}

Lead

{track.lead_name}

Team

{track.team_size} members

Progress {track.progress}%
))}
)} {/* Publications Tab */} {publications.length === 0 ? (

No publications yet

) : ( )}
{/* Bounties Tab */} {bounties.length === 0 ? (

No active research bounties at this time

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

{bounty.title}

${bounty.reward.toLocaleString()}

{bounty.description}

{bounty.difficulty} {bounty.applicants_count} applicants
))}
)}
{/* IP Portfolio - Admin Only */} {ipPortfolio.length > 0 && ( IP Portfolio Proprietary intellectual property assets
{ipPortfolio.map((item) => ( ))}
IP Name Type Status Licensed To
{item.name} {item.type.replace("-", " ")} {item.status} {item.licensed_to}
)}
); }