1+ "use client" ;
2+
3+ import { Card , CardHeader , CardTitle , CardContent } from "@/components/ui/card" ;
4+ import { Button } from "@/components/ui/button" ;
5+ import { Download , ArrowUp } from "lucide-react" ;
6+
7+ type Report = {
8+ cover_letter ?: string ;
9+ submission ?: {
10+ job_description ?: {
11+ role_name ?: string ;
12+ company_name ?: string ;
13+ } ;
14+ user_created ?: { first_name ?: string ; last_name ?: string } ;
15+ } ;
16+ } ;
17+
18+ interface CoverLetterCardProps {
19+ report : Report ;
20+ candidateName : string ;
21+ roleName : string ;
22+ companyName : string ;
23+ }
24+
25+ export default function CoverLetterCard ( { report, candidateName, roleName, companyName } : CoverLetterCardProps ) {
26+ const generateCoverLetterPDF = ( ) => {
27+ if ( ! report ?. cover_letter ) return ;
28+
29+ // Create a temporary div for the cover letter content
30+ const tempDiv = document . createElement ( 'div' ) ;
31+ tempDiv . style . position = 'absolute' ;
32+ tempDiv . style . left = '-9999px' ;
33+ tempDiv . style . width = '210mm' ;
34+ tempDiv . style . padding = '20mm' ;
35+ tempDiv . style . fontFamily = 'Arial, sans-serif' ;
36+ tempDiv . style . fontSize = '12px' ;
37+ tempDiv . style . lineHeight = '1.6' ;
38+ tempDiv . style . color = 'black' ;
39+ tempDiv . style . backgroundColor = 'white' ;
40+
41+ tempDiv . innerHTML = `
42+ <div style="text-align: center; margin-bottom: 40px; border-bottom: 2px solid #000; padding-bottom: 20px;">
43+ <h1 style="margin: 0; font-size: 24px; font-weight: bold;">Cover Letter</h1>
44+ <p style="margin: 10px 0 0 0; font-size: 14px; color: #666;">${ candidateName } - ${ roleName } @ ${ companyName } </p>
45+ </div>
46+ <div style="white-space: pre-wrap; text-align: justify;">${ report . cover_letter } </div>
47+ ` ;
48+
49+ document . body . appendChild ( tempDiv ) ;
50+
51+ const printWindow = window . open ( '' , '_blank' ) ;
52+ if ( printWindow ) {
53+ printWindow . document . write ( `
54+ <html>
55+ <head>
56+ <title>Cover Letter - ${ candidateName } </title>
57+ <style>
58+ @media print {
59+ body { margin: 0; }
60+ @page { margin: 20mm; }
61+ }
62+ </style>
63+ </head>
64+ <body>
65+ ${ tempDiv . innerHTML }
66+ </body>
67+ </html>
68+ ` ) ;
69+ printWindow . document . close ( ) ;
70+ printWindow . print ( ) ;
71+ }
72+
73+ // Clean up
74+ document . body . removeChild ( tempDiv ) ;
75+ } ;
76+
77+ if ( ! report . cover_letter ) return null ;
78+
79+ return (
80+ < Card className = "w-full" >
81+ < CardHeader >
82+ < CardTitle className = "text-center text-lg" >
83+ Cover Letter
84+ </ CardTitle >
85+ </ CardHeader >
86+ < CardContent className = "space-y-6" >
87+ < div className = "text-center" >
88+ < p className = "text-sm text-gray-600 mb-4" >
89+ Personalized cover letter generated based on your profile and the job requirements.
90+ </ p >
91+ </ div >
92+
93+ { /* Cover Letter Preview */ }
94+ < h3 className = "text-sm font-medium text-gray-900 mb-3" > Preview</ h3 >
95+ < div className = "bg-gray-50 rounded-lg p-4 max-h-64 overflow-y-auto" >
96+ < div className = "text-sm text-gray-800 whitespace-pre-wrap leading-relaxed" >
97+ { report . cover_letter }
98+ </ div >
99+ </ div >
100+
101+ { /* Prompt Section */ }
102+ < div className = "filter grayscale opacity-50 pointer-events-none" >
103+ < p className = "text-sm text-gray-800 mb-3" >
104+ Want to personalize your cover letter further? Use the prompt below to regenerate it with specific requirements or tone adjustments.
105+ </ p >
106+ < div className = "relative" >
107+ < input
108+ type = "text"
109+ placeholder = "Coming soon... (e.g., 'Make it more formal', 'Add emphasis on leadership experience')"
110+ className = "w-full px-4 py-3 pr-12 text-sm border rounded-full focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"
111+ disabled
112+ />
113+ < button className = "absolute right-2 top-1/2 -translate-y-1/2 p-2 bg-primary-600 hover:bg-primary-700 text-white rounded-full focus:outline-none focus:ring-offset-2" disabled >
114+ < ArrowUp className = "h-4 w-4" />
115+ </ button >
116+ </ div >
117+ < div className = "absolute inset-0 flex items-center justify-center" >
118+ < span className = "bg-white px-4 py-2 rounded-full text-sm font-bold text-gray-800 shadow-lg border" >
119+ Coming Soon
120+ </ span >
121+ </ div >
122+ </ div >
123+
124+ < Button
125+ onClick = { generateCoverLetterPDF }
126+ className = "flex items-center gap-2 mx-auto"
127+ >
128+ < Download className = "h-4 w-4" />
129+ Download Cover Letter PDF
130+ </ Button >
131+ </ CardContent >
132+ </ Card >
133+ ) ;
134+ }
0 commit comments