Personalized Self-Care Routine Generator

Personalized Self-Care

Routine Generator

${item.details}

`).join('')}
`; }; 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 && !validateAndStoreAnswer()) { alert('Please make a selection to continue.'); return; } currentStep += direction; if (currentStep === 2) { generateRoutine(); } renderStep(); }; const validateAndStoreAnswer = () => { 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 generateRoutine = () => { const feeling = userAnswers.feeling; const time = userAnswers.time; finalRoutine = ROUTINE_DATA[feeling][time]; }; const handlePdfDownload = () => { if (finalRoutine.length === 0) return; const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFont('helvetica', 'bold').setFontSize(20); doc.text('Your Personalized Self-Care Routine', 105, 20, { align: 'center' }); doc.setFont('helvetica', 'normal').setFontSize(12); doc.text(`For when you're feeling: ${userAnswers.feeling}`, 14, 35); doc.text(`With this much time: ${userAnswers.time}`, 14, 42); const tableData = finalRoutine.map(item => [item.name, item.details]); doc.autoTable({ startY: 50, head: [['Activity', 'Suggestion']], body: tableData, theme: 'grid', headStyles: { fillColor: '#7c3aed' }, columnStyles: { 1: { cellWidth: 'auto' } } }); doc.save('My_Self_Care_Routine.pdf'); }; // --- EVENT LISTENERS --- nextBtn.addEventListener('click', () => handleNavigate(1)); prevBtn.addEventListener('click', () => handleNavigate(-1)); wizardContainer.addEventListener('click', (e) => { if (e.target.id === 'download-pdf-btn') { handlePdfDownload(); } }); // --- INITIALIZATION --- renderStep(); });
Scroll to Top