"use client"; import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { useSession } from "next-auth/react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { OrchestratorChat } from "@/components/OrchestratorChat"; import { AtlasChat } from "@/components/AtlasChat"; import { Terminal, Loader2, RefreshCw, } from "lucide-react"; import { toast } from "sonner"; interface Project { id: string; name: string; productName: string; productVision?: string; status?: string; currentPhase?: string; theiaWorkspaceUrl?: string; stage?: 'discovery' | 'architecture' | 'building' | 'active'; prd?: string; } export default function ProjectOverviewPage() { const params = useParams(); const projectId = params.projectId as string; const { status: authStatus } = useSession(); const [project, setProject] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [refreshing, setRefreshing] = useState(false); const [provisioning, setProvisioning] = useState(false); const fetchProject = async () => { try { const res = await fetch(`/api/projects/${projectId}`); if (!res.ok) { const err = await res.json(); throw new Error(err.error || "Failed to load project"); } const data = await res.json(); setProject(data.project); setError(null); } catch (err) { setError(err instanceof Error ? err.message : "Unknown error"); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { if (authStatus === "authenticated") fetchProject(); else if (authStatus === "unauthenticated") setLoading(false); }, [authStatus, projectId]); const handleRefresh = () => { setRefreshing(true); fetchProject(); }; const handleProvisionWorkspace = async () => { setProvisioning(true); try { const res = await fetch(`/api/projects/${projectId}/workspace`, { method: 'POST' }); const data = await res.json(); if (res.ok && data.workspaceUrl) { toast.success('Workspace provisioned — starting up…'); await fetchProject(); } else { toast.error(data.error || 'Failed to provision workspace'); } } catch { toast.error('An error occurred'); } finally { setProvisioning(false); } }; if (loading) { return (
); } if (error || !project) { return (

{error ?? "Project not found"}

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

{project.productName}

{project.productVision && (

{project.productVision}

)}
{project.status ?? "active"} {project.currentPhase && ( {project.currentPhase} )}
{project.theiaWorkspaceUrl ? ( ) : ( )}
{/* ── Agent Panel — Atlas for discovery, Orchestrator once PRD is done ── */} {(!project.stage || project.stage === 'discovery') ? ( ) : ( )}
); }