`;
resultsList.appendChild(card);
});
resultsContainer.classList.remove('hidden');
resultsContainer.classList.add('fade-in');
}
function downloadPdf() {
if (analysisResults.length === 0) {
showError("No analysis results to download.");
return;
}
const { jsPDF } = window.jspdf;
if (!jsPDF) {
showError("PDF library is not available.");
return;
}
const doc = new jsPDF();
doc.setFontSize(20);
doc.text("Resume Screening Report", 105, 20, { align: 'center' });
doc.setFontSize(14);
doc.text("Job Description", 14, 40);
const jdLines = doc.splitTextToSize(jobDescInput.value.trim(), 180);
doc.setFontSize(10);
doc.setTextColor(100);
doc.text(jdLines, 14, 48);
const jdHeight = (jdLines.length * 5) + 15;
const tableData = analysisResults.map(res => [
res.candidateIdentifier,
`${res.matchScore}%`,
res.summary
]);
doc.autoTable({
head: [['Candidate', 'Match Score', 'Summary']],
body: tableData,
startY: 48 + jdHeight,
theme: 'grid',
headStyles: { fillColor: [30, 64, 175] }, // blue-800
styles: { cellPadding: 2.5, fontSize: 9 },
});
doc.save('Resume_Screening_Report.pdf');
}
// --- UI Helper Functions ---
function toggleLoading(isLoading) {
analyzeBtn.disabled = isLoading;
loader.classList.toggle('hidden', !isLoading);
analyzeBtnText.classList.toggle('hidden', isLoading);
}
function getScoreColor(score) {
if (score >= 85) return '#16a34a'; // green-600
if (score >= 70) return '#f59e0b'; // amber-500
return '#dc2626'; // red-600
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.remove('hidden');
}
function hideError() {
errorMessage.classList.add('hidden');
}
});