'use client' import { useState } from 'react' import { useParams } from 'next/navigation' import Link from 'next/link' import type { Route } from 'next' import { useSession } from 'next-auth/react' import { trpc } from '@/lib/trpc/client' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card' import { Skeleton } from '@/components/ui/skeleton' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { StatusTracker } from '@/components/shared/status-tracker' import { MentorChat } from '@/components/shared/mentor-chat' import { RequirementUploadList } from '@/components/shared/requirement-upload-slot' import { ArrowLeft, FileText, Clock, AlertCircle, AlertTriangle, Download, Video, File, Users, Crown, MessageSquare, } from 'lucide-react' const statusColors: Record = { DRAFT: 'secondary', SUBMITTED: 'default', UNDER_REVIEW: 'default', ELIGIBLE: 'default', SEMIFINALIST: 'success', FINALIST: 'success', WINNER: 'success', REJECTED: 'destructive', } const fileTypeIcons: Record = { EXEC_SUMMARY: FileText, BUSINESS_PLAN: FileText, PRESENTATION: FileText, VIDEO_PITCH: Video, VIDEO: Video, OTHER: File, SUPPORTING_DOC: File, } const fileTypeLabels: Record = { EXEC_SUMMARY: 'Executive Summary', BUSINESS_PLAN: 'Business Plan', PRESENTATION: 'Presentation', VIDEO_PITCH: 'Video Pitch', VIDEO: 'Video', OTHER: 'Other Document', SUPPORTING_DOC: 'Supporting Document', } export function SubmissionDetailClient() { const params = useParams() const { data: session } = useSession() const projectId = params.id as string const [activeTab, setActiveTab] = useState('details') const { data: statusData, isLoading, error } = trpc.applicant.getSubmissionStatus.useQuery( { projectId }, { enabled: !!session?.user } ) const { data: mentorMessages, isLoading: messagesLoading } = trpc.applicant.getMentorMessages.useQuery( { projectId }, { enabled: !!session?.user && activeTab === 'mentor' } ) const utils = trpc.useUtils() const sendMessage = trpc.applicant.sendMentorMessage.useMutation({ onSuccess: () => { utils.applicant.getMentorMessages.invalidate({ projectId }) }, }) if (isLoading) { return (
) } if (error || !statusData) { return (
Error {error?.message || 'Submission not found'}
) } const { project, timeline, currentStatus } = statusData const isDraft = !project.submittedAt return (
{/* Header */}

{project.title}

{currentStatus.replace('_', ' ')}

{project.round?.program?.year ? `${project.round.program.year} Edition` : ''}{project.round?.name ? ` - ${project.round.name}` : ''}

{/* Draft warning */} {isDraft && ( Draft Submission This submission has not been submitted yet. You can continue editing and submit when ready. )} Details Documents Mentor {/* Details Tab */}
{/* Main content */}
{/* Project details */} Project Details {project.teamName && (

Team/Organization

{project.teamName}

)} {project.description && (

Description

{project.description}

)} {project.tags && project.tags.length > 0 && (

Tags

{project.tags.map((tag) => ( {tag} ))}
)}
{/* Metadata */} {project.metadataJson && Object.keys(project.metadataJson as Record).length > 0 && ( Additional Information
{Object.entries(project.metadataJson as Record).map(([key, value]) => (
{key.replace(/_/g, ' ')}
{String(value)}
))}
)}
{/* Sidebar */}
{/* Status timeline */} Status Timeline {/* Dates */} Key Dates
Created {new Date(project.createdAt).toLocaleDateString()}
{project.submittedAt && (
Submitted {new Date(project.submittedAt).toLocaleDateString()}
)}
Last Updated {new Date(project.updatedAt).toLocaleDateString()}
{/* Team Members */} {'teamMembers' in project && project.teamMembers && (
Team
{(project.teamMembers as Array<{ id: string; role: string; user: { name: string | null; email: string } }>).map((member) => (
{member.role === 'LEAD' ? ( ) : ( {member.user.name?.charAt(0).toUpperCase() || '?'} )}

{member.user.name || member.user.email}

{member.role === 'LEAD' ? 'Team Lead' : member.role === 'ADVISOR' ? 'Advisor' : 'Member'}

))}
)}
{/* Documents Tab */} {/* File Requirements Upload Slots */} {project.roundId && (
)} Uploaded Documents Documents submitted with your application {project.files.length === 0 ? (

No documents uploaded

) : (
{project.files.map((file) => { const Icon = fileTypeIcons[file.fileType] || File const fileRecord = file as typeof file & { isLate?: boolean; roundId?: string | null } return (

{file.fileName}

{fileRecord.isLate && ( Submitted late )}

{fileTypeLabels[file.fileType] || file.fileType}

) })}
)}
{/* Mentor Tab */} Mentor Communication Chat with your assigned mentor { await sendMessage.mutateAsync({ projectId, message }) }} isLoading={messagesLoading} isSending={sendMessage.isPending} />
) }