`;
}
function downloadGuidePDF() {
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('Collagen Optimization Guide', margin, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(108, 117, 125);
doc.text(`Guide Generated: ${new Date().toLocaleDateString('en-US')}`, margin, currentY);
currentY += 40;
const addSection = (title, icon, recommendation) => {
if (currentY > doc.internal.pageSize.getHeight() - 100) {
doc.addPage();
currentY = margin;
}
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(33, 37, 41);
doc.text(`${icon} ${title}`, margin, currentY);
const ratingText = recommendation.rating.toUpperCase();
const ratingColor = recommendation.rating === 'good' ? [34, 197, 94] : recommendation.rating === 'average' ? [234, 179, 8] : [239, 68, 68];
doc.setFont('helvetica', 'bold');
doc.setFontSize(10);
doc.setTextColor(ratingColor[0], ratingColor[1], ratingColor[2]);
doc.text(ratingText, docWidth - margin, currentY, { align: 'right' });
currentY += 20;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor(55, 65, 81);
const textLines = doc.splitTextToSize(recommendation.text, docWidth - margin * 2);
doc.text(textLines, margin, currentY);
currentY += textLines.length * 12 + 20;
};
addSection('Dietary Habits', '🍎', lastGuide.diet);
addSection('Sun Protection', '☀️', lastGuide.sun);
addSection('Lifestyle Factors', '🏃', lastGuide.lifestyle);
addSection('Age-Related Factors', '⏳', lastGuide.age);
// Skincare section with autoTable
if (currentY > doc.internal.pageSize.getHeight() - 150) {
doc.addPage();
currentY = margin;
}
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(33, 37, 41);
doc.text('🧴 Topical Skincare Recommendations', margin, currentY);
currentY += 20;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
const skincareIntro = doc.splitTextToSize(lastGuide.skincare.base, docWidth - margin * 2);
doc.text(skincareIntro, margin, currentY);
currentY += skincareIntro.length * 12 + 10;
doc.autoTable({
startY: currentY,
head: [['Product Type', 'Recommendation']],
body: Object.entries(lastGuide.skincare.options),
theme: 'grid',
headStyles: { fillColor: [79, 70, 229] },
styles: { font: 'helvetica', fontSize: 9 },
});
// Footer
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFontSize(8);
doc.setTextColor(108, 117, 125);
doc.text('This guide provides general recommendations. Consult a healthcare professional for medical advice.', docWidth / 2, pageHeight - 20, { align: 'center' });
doc.save('My-Collagen-Guide.pdf');
}