Personalized Recommendations
${result.recommendations.map(rec => `- ${rec}
`).join('')}
`;
}
function downloadResultPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const docWidth = doc.internal.pageSize.getWidth();
const margin = 40;
let currentY = margin;
// Header
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.setTextColor(79, 70, 229);
doc.text('Caffeine Sensitivity Report', margin, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(108, 117, 125);
doc.text(`Report Date: ${new Date().toLocaleDateString('en-US')}`, margin, currentY);
currentY += 40;
const addSectionHeader = (title) => {
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(33, 37, 41);
doc.text(title, margin, currentY);
currentY += 15;
doc.setDrawColor(222, 226, 230);
doc.line(margin, currentY, docWidth - margin, currentY);
currentY += 25;
};
// Assessment Result
addSectionHeader('Assessment Result');
doc.setFontSize(12);
doc.text('Assessed Sensitivity Level:', margin, currentY);
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
const levelColor = lastResult.level === 'High' ? [220, 38, 38] : lastResult.level === 'Moderate' ? [202, 138, 4] : [22, 163, 74];
doc.setTextColor(levelColor[0], levelColor[1], levelColor[2]);
doc.text(lastResult.level, margin + 180, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor(55, 65, 81);
const descLines = doc.splitTextToSize(lastResult.description, docWidth - margin * 2);
doc.text(descLines, margin, currentY);
currentY += descLines.length * 12 + 30;
// Recommendations
addSectionHeader('Personalized Recommendations');
doc.setFontSize(11);
lastResult.recommendations.forEach(rec => {
doc.text(`• ${rec}`, margin, currentY, { maxWidth: docWidth - margin * 2 });
currentY += 20;
});
currentY += 20;
// Your Answers
addSectionHeader('Your Assessment Answers');
doc.autoTable({
startY: currentY,
body: Object.entries(lastResult.inputs),
theme: 'plain',
styles: { font: 'helvetica', fontSize: 10 },
columnStyles: { 0: { fontStyle: 'bold' } }
});
// Footer
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFont('helvetica', 'normal');
doc.setFontSize(8);
doc.setTextColor(108, 117, 125);
doc.text('This report is for informational purposes and is not a substitute for professional medical advice.', docWidth / 2, pageHeight - 20, { align: 'center' });
doc.save('Caffeine-Sensitivity-Report.pdf');
}