Disclaimer: This is a sample plan for informational purposes only. Consult with a healthcare provider before starting any new supplement regimen. Dosages are general suggestions and may not be appropriate for everyone.
Download Plan as PDF
`;
};
const updateUI = () => {
prevBtn.style.visibility = currentStep > 0 ? 'visible' : 'hidden';
navigationContainer.style.display = currentStep === 2 ? 'none' : 'flex';
stepIndicator.textContent = `Step ${currentStep + 1} of 2`;
};
const handleNavigate = (direction) => {
if (direction === 1 && !validateAndStoreAnswers()) {
alert('Please make a selection to continue.');
return;
}
currentStep += direction;
if (currentStep === 2) {
generatePlan();
}
renderStep();
};
const validateAndStoreAnswers = () => {
const radioGroup = document.querySelector(`#step-${currentStep} input[type="radio"]`);
if (radioGroup) {
const groupName = radioGroup.name;
const selected = document.querySelector(`input[name="${groupName}"]:checked`);
if (selected) {
userAnswers[groupName] = selected.value;
return true;
}
return false;
}
return true;
};
const generatePlan = () => {
const primaryGoal = userAnswers.primary_goal;
const secondaryGoal = userAnswers.secondary_goal;
finalPlan = PLAN_DATA[primaryGoal].options[secondaryGoal];
};
const handlePdfDownload = () => {
if (finalPlan.length === 0) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFont('helvetica', 'bold').setFontSize(20);
doc.text('Your Personalized Supplement Plan', 105, 20, { align: 'center' });
doc.setFont('helvetica', 'normal').setFontSize(12);
doc.text(`For Your Goal: ${userAnswers.primary_goal} - ${userAnswers.secondary_goal}`, 105, 28, { align: 'center' });
const tableData = finalPlan.map(item => [item.name, item.dosage, item.timing, item.reason]);
doc.autoTable({
startY: 40,
head: [['Supplement', 'Dosage', 'Timing', 'Reason']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: '#0ea5e9' },
columnStyles: { 3: { cellWidth: 'auto' } }
});
const disclaimerText = "Disclaimer: This is a sample plan for informational purposes only. Consult with a healthcare provider before starting any new supplement regimen.";
const splitDisclaimer = doc.splitTextToSize(disclaimerText, 180);
doc.setFontSize(10).setTextColor('#475569').text(splitDisclaimer, 14, doc.autoTable.previous.finalY + 15);
doc.save('My_Supplement_Plan.pdf');
};
// --- EVENT LISTENERS ---
nextBtn.addEventListener('click', () => handleNavigate(1));
prevBtn.addEventListener('click', () => handleNavigate(-1));
// Event delegation for dynamically created PDF button
wizardContainer.addEventListener('click', (e) => {
if (e.target.id === 'download-pdf-btn') {
handlePdfDownload();
}
});
// --- INITIALIZATION ---
renderStep();
});