"use client"; import { useState, useEffect } from "react"; import { motion } from "framer-motion"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Badge } from "@/components/ui/badge"; import { ArrowLeft, Download, Star, Briefcase, GraduationCap, Code, Languages, FolderOpen, Loader2, BookOpen, Users, Award, Trophy, LinkedinIcon, GithubIcon, PenBox, ExternalLink, } from "lucide-react"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { useSession } from "next-auth/react"; import { renderMarkdown } from "@/lib/markdown-renderer"; interface AnalysisData { resume: { id: string; customName: string; rawText: string; uploadDate: string; showInCentral: boolean; user: { id: string; name: string | null; email: string | null; }; }; analysis: { id: string; name: string | null; email: string | null; contact: string | null; linkedin?: string | null; github?: string | null; blog?: string | null; portfolio?: string | null; predictedField: string | null; skillsAnalysis: Array<{ skill_name: string; percentage: number; }>; recommendedRoles: string[]; languages: Array<{ language: string; }>; education: Array<{ education_detail: string; }>; workExperience: Array<{ role: string; company_and_duration: string; bullet_points: string[]; }>; projects: Array<{ title: string; technologies_used: string[]; description: string; live_link?: string; repo_link?: string; }>; publications: Array<{ title: string; authors?: string; journal_conference?: string; year?: string; doi?: string; url?: string; }> | null; positionsOfResponsibility: Array<{ title: string; organization: string; duration?: string; description?: string; }> | null; certifications: Array<{ name: string; issuing_organization: string; issue_date?: string; expiry_date?: string; credential_id?: string; url?: string; }> | null; achievements: Array<{ title: string; description?: string; year?: string; category?: string; }> | null; uploadedAt: string; }; } export default function AnalysisPage() { const params = useParams(); const router = useRouter(); const { data: session, status } = useSession(); const [analysisData, setAnalysisData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (status === "loading") return; if (!session) { router.push("/auth/signin"); return; } const fetchAnalysis = async () => { try { const response = await fetch(`/api/resumes/${params.id}`); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.message || "Failed to fetch analysis"); } const result = await response.json(); setAnalysisData(result.data); } catch (err) { setError( err instanceof Error ? err.message : "Failed to fetch analysis" ); } finally { setLoading(false); } }; if (params.id) { fetchAnalysis(); } }, [params.id, session, status, router]); if (loading) { return (

Loading analysis...

); } if (error) { return (

{error}

); } if (!analysisData) { return (

No analysis data found

); } const { resume, analysis } = analysisData; return (

Resume Analysis

{analysis.name || "Candidate"} - {resume.customName}

{/* Main Content */}
{/* Skills Analysis */} Skills Analysis {analysis.skillsAnalysis && analysis.skillsAnalysis.length > 0 ? ( analysis.skillsAnalysis.map((skill, index) => (
{skill.skill_name} {skill.percentage}%
)) ) : (

No skills analysis available

)}
{/* Work Experience */} Work Experience {analysis.workExperience && analysis.workExperience.length > 0 ? ( analysis.workExperience.map((work, index) => (

{work.role}

{work.company_and_duration}

{work.bullet_points && work.bullet_points.length > 0 && (
    {work.bullet_points.map((point, i) => (
  • {renderMarkdown(point)}
  • ))}
)}
)) ) : (

No work experience data available

)}
{/* Projects Section */} Projects {analysis.projects && analysis.projects.length > 0 ? ( analysis.projects.map((project, index) => (

{project.title}

{(project.live_link || project.repo_link) && (
{project.live_link && ( )} {project.repo_link && ( )}
)}
{project.technologies_used && project.technologies_used.length > 0 && (
{project.technologies_used.map((tech, i) => ( {tech} ))}
)}
{renderMarkdown(project.description)}
)) ) : (

No projects data available

)}
{/* Publications Section */} {analysis.publications && analysis.publications.length > 0 && ( Publications {analysis.publications.map((publication, index) => (

{publication.title}

{publication.authors && (

Authors: {publication.authors}

)} {publication.journal_conference && (

{publication.journal_conference}

)} {publication.year && (

Year: {publication.year}

)} {publication.doi && (

DOI: {publication.doi}

)} {publication.url && ( View Publication )}
))}
)} {/* Positions of Responsibility Section */} {analysis.positionsOfResponsibility && analysis.positionsOfResponsibility.length > 0 && ( Positions of Responsibility {analysis.positionsOfResponsibility.map( (position, index) => (

{position.title}

{position.organization}

{position.duration && (

{position.duration}

)} {position.description && (
{renderMarkdown(position.description)}
)}
) )}
)} {/* Certifications Section */} {analysis.certifications && analysis.certifications.length > 0 && ( Certifications {analysis.certifications.map((certification, index) => (

{certification.name}

{certification.issuing_organization}

{certification.issue_date && (

Issued: {certification.issue_date}

)} {certification.expiry_date && (

Expires: {certification.expiry_date}

)} {certification.credential_id && (

ID: {certification.credential_id}

)} {certification.url && ( View Certificate )}
))}
)} {/* Achievements Section */} {analysis.achievements && analysis.achievements.length > 0 && ( Achievements {analysis.achievements.map((achievement, index) => (

{achievement.title}

{achievement.category && ( {achievement.category} )} {achievement.year && (

{achievement.year}

)} {achievement.description && (
{renderMarkdown(achievement.description)}
)}
))}
)}
{/* Sidebar */}
{/* Candidate Info */} Candidate Information {analysis.name && (
Name:

{analysis.name}

)} {analysis.email && (
Email:

{analysis.email}

)} {analysis.contact && (
Contact:

{analysis.contact}

)} {analysis.predictedField && (
Predicted Field:

{analysis.predictedField}

)} {(analysis.linkedin || analysis.github || analysis.blog || analysis.portfolio) && (
Links:
{analysis.linkedin && ( {(() => { const link = analysis.linkedin!; try { const url = new URL(link); // show everything after hostname (strip leading '/') return ( url.pathname.replace(/^\/+/, "") || url.search.replace(/^\?/, "") || url.hash.replace(/^#/, "") ); } catch { const idx = link.indexOf("linkedin.com/"); return idx !== -1 ? link.slice(idx + "linkedin.com/".length) : link; } })()} )} {analysis.github && ( {(() => { const link = analysis.github!; try { const url = new URL(link); // show everything after hostname (strip leading '/') return ( url.pathname.replace(/^\/+/, "") || url.search.replace(/^\?/, "") || url.hash.replace(/^#/, "") ); } catch { const idx = link.indexOf("github.com/"); return idx !== -1 ? link.slice(idx + "github.com/".length) : link; } })()} )} {analysis.blog && ( {(() => { const link = analysis.blog!; try { const url = new URL(link); const display = `${url.host}${url.pathname}${url.search}${url.hash}`.replace( /\/$/, "" ); return display; } catch { return link .replace(/^https?:\/\//, "") .replace(/\/$/, ""); } })()} )} {analysis.portfolio && ( {(() => { const link = analysis.portfolio!; try { const url = new URL(link); const display = `${url.host}${url.pathname}${url.search}${url.hash}`.replace( /\/$/, "" ); return display; } catch { return link .replace(/^https?:\/\//, "") .replace(/\/$/, ""); } })()} )}
)}
{/* Recommended Roles */} Recommended Roles
{analysis.recommendedRoles && analysis.recommendedRoles.length > 0 ? ( analysis.recommendedRoles.map((role, index) => ( {role} )) ) : (

No role recommendations available

)}
{/* Languages */} Languages
{analysis.languages && analysis.languages.length > 0 ? ( analysis.languages.map((lang, index) => (
{lang.language}
)) ) : (

No language information available

)}
{/* Education */} Education
{analysis.education && analysis.education.length > 0 ? ( analysis.education.map((edu, index) => (

{edu.education_detail}

)) ) : (

No education information available

)}
); }