No concerns selected. Go back to the previous tab to make your selections.
`;
return;
}
const recommendedVitamins = new Set();
selectedConcerns.forEach(c => c.vitamins.forEach(v => recommendedVitamins.add(v)));
let outputHTML = `
Your Personalized Vitamin Guide
`;
Array.from(recommendedVitamins).forEach(vitaminId => {
const vitamin = vitaminData[vitaminId];
if (!vitamin) return;
outputHTML += `
${vitamin.name}
${vitamin.description}
Top Food Sources:
${vitamin.foods.map(food => `${food}`).join('')}
`;
});
recommendationsOutput.innerHTML = outputHTML;
};
// --- PDF Generation ---
const generatePDF = () => {
if (!lastSelections || lastSelections.length === 0) {
alert("Please select your concerns on the first tab before exporting.");
return;
}
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
const margin = 15;
const pdfWidth = pdf.internal.pageSize.getWidth();
let currentY = margin;
// Header
pdf.setFont('helvetica', 'bold');
pdf.setFontSize(20);
pdf.text('Hair & Skin Vitamin Report', pdfWidth / 2, currentY, { align: 'center' });
currentY += 10;
pdf.setFont('helvetica', 'normal');
pdf.setFontSize(11);
pdf.text(`Generated on: ${new Date().toLocaleDateString()}`, pdfWidth / 2, currentY, { align: 'center' });
currentY += 10;
pdf.setDrawColor(220, 220, 220);
pdf.line(margin, currentY, pdfWidth - margin, currentY);
currentY += 15;
// Selected Concerns
pdf.setFontSize(14);
pdf.setFont('helvetica', 'bold');
pdf.text('Your Selected Concerns:', margin, currentY);
currentY += 8;
pdf.setFontSize(11);
pdf.setFont('helvetica', 'normal');
lastSelections.forEach(concern => {
pdf.text(`• ${concern.label}`, margin + 5, currentY);
currentY += 7;
});
currentY += 5;
// Recommendations
const recommendedVitamins = new Set();
lastSelections.forEach(c => c.vitamins.forEach(v => recommendedVitamins.add(v)));
pdf.setFontSize(14);
pdf.setFont('helvetica', 'bold');
pdf.text('Recommended Vitamins & Nutrients:', margin, currentY);
currentY += 10;
Array.from(recommendedVitamins).forEach(vitaminId => {
const vitamin = vitaminData[vitaminId];
if (!vitamin) return;
if (currentY > 250) { // Check for new page
pdf.addPage();
currentY = margin;
}
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text(vitamin.name, margin, currentY);
currentY += 6;
pdf.setFontSize(10);
pdf.setFont('helvetica', 'normal');
const descLines = pdf.splitTextToSize(vitamin.description, pdfWidth - (margin * 2));
pdf.text(descLines, margin, currentY);
currentY += descLines.length * 4 + 4;
pdf.setFont('helvetica', 'bold');
pdf.text('Food Sources:', margin, currentY);
currentY += 5;
pdf.setFont('helvetica', 'normal');
const foodLines = pdf.splitTextToSize(vitamin.foods.join(', '), pdfWidth - (margin * 2) - 5);
pdf.text(foodLines, margin + 5, currentY);
currentY += foodLines.length * 4 + 8;
});
// Footer
const pageHeight = pdf.internal.pageSize.getHeight();
pdf.line(margin, pageHeight - 20, pdfWidth - margin, pageHeight - 20);
pdf.setFontSize(9);
pdf.setFont('helvetica', 'italic');
pdf.text('This report is for informational purposes only and is not medical advice.', pdfWidth / 2, pageHeight - 15, { align: 'center' });
pdf.save('My-Hair-Skin-Vitamin-Report.pdf');
};
init();
});