`).join('');
resultsPlaceholder.classList.add('hidden');
resultsContent.classList.remove('hidden');
}
function downloadPDF() {
if (generatedRoutine.length === 0) {
alert('Please generate your routine first.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const pageW = doc.internal.pageSize.getWidth();
const margin = 40;
let currentY = 0;
const primaryColor = [37, 99, 235], grayColor = [107, 114, 128], blackColor = [17, 24, 39];
// --- HEADER ---
doc.setFillColor(...primaryColor);
doc.rect(0, 0, pageW, 80, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(24);
doc.setTextColor(255, 255, 255);
doc.text('Personalized Stretching Routine', margin, 50);
currentY = 110;
// --- SUMMARY ---
const summaryText = document.getElementById('routine-summary-text').textContent;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor(...grayColor);
doc.text(summaryText, margin, currentY);
currentY += 30;
// --- TABLE ---
const routineData = generatedRoutine.map((stretch, i) => [
i + 1,
stretch.name,
stretch.desc,
`${stretch.duration}s`
]);
doc.autoTable({
startY: currentY,
head: [['#', 'Stretch Name', 'Instructions', 'Duration']],
body: routineData,
theme: 'grid',
headStyles: { fillColor: [59, 130, 246] },
styles: { font: 'helvetica', fontSize: 9, cellPadding: 6 },
columnStyles: {
0: { cellWidth: 30 },
1: { cellWidth: 120 },
3: { cellWidth: 60, halign: 'center' }
}
});
currentY = doc.lastAutoTable.finalY + 30;
// --- FOOTER ---
const pageH = doc.internal.pageSize.getHeight();
doc.setDrawColor(...grayColor);
doc.line(margin, pageH - 60, pageW - margin, pageH - 60);
doc.setFont('helvetica', 'normal');
doc.setFontSize(8);
doc.setTextColor(...grayColor);
const footerText = 'This routine is generated based on your selections. Always listen to your body and avoid any movements that cause pain. Consult a professional for personalized health advice.';
doc.text(doc.splitTextToSize(footerText, pageW - (margin * 2)), margin, pageH - 45);
doc.save('My-Stretching-Routine.pdf');
}
// --- EVENT LISTENERS ---
prevBtn.addEventListener('click', () => {
if (currentTab > 1) {
currentTab--;
updateUI();
}
});
nextBtn.addEventListener('click', () => {
if (currentTab === 1) {
currentTab++;
} else if (currentTab === 2) {
generateRoutine();
}
updateUI();
});
pdfDownloadBtn.addEventListener('click', downloadPDF);
// --- KICKOFF ---
populateOptions();
updateUI();
});