`;
}
function downloadRoutinePDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const docWidth = doc.internal.pageSize.getWidth();
const margin = 40;
let currentY = margin;
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.setTextColor(79, 70, 229);
doc.text('Personalized Foam Rolling Routine', margin, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(108, 117, 125);
doc.text(`Report Generated: ${new Date().toLocaleDateString('en-US')}`, margin, currentY);
currentY += 40;
const addSectionHeader = (title) => {
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(33, 37, 41);
doc.text(title, margin, currentY);
currentY += 15;
doc.setDrawColor(222, 226, 230);
doc.line(margin, currentY, docWidth - margin, currentY);
currentY += 20;
};
addSectionHeader('Your Profile');
doc.setFont('helvetica', 'normal');
doc.setFontSize(12);
doc.text(`Fitness Level: ${lastRoutine.fitnessLevel}`, margin, currentY);
currentY += 20;
doc.text(`Primary Goal: ${lastRoutine.primaryGoal}`, margin, currentY);
currentY += 20;
doc.text(`Total Duration: ${lastRoutine.duration} minutes`, margin, currentY);
currentY += 40;
addSectionHeader('Routine Steps');
lastRoutine.steps.forEach((step, index) => {
if (currentY > doc.internal.pageSize.getHeight() - 100) {
doc.addPage();
currentY = margin;
}
doc.setFont('helvetica', 'bold');
doc.setFontSize(12);
doc.setTextColor(79, 70, 229);
doc.text(`${index + 1}. ${step.muscle}`, margin, currentY);
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(33, 37, 41);
const instructionText = doc.splitTextToSize(step.instruction, docWidth - (margin * 2) - 20);
doc.text(instructionText, margin + 20, currentY + 18);
currentY += (instructionText.length * 10) + 25;
doc.setFont('helvetica', 'bold');
doc.text(`Duration: ${step.duration} seconds`, margin + 20, currentY);
currentY += 30;
});
const pageHeight = doc.internal.pageSize.getHeight();
doc.setDrawColor(222, 226, 230);
doc.line(margin, pageHeight - 30, docWidth - margin, pageHeight - 30);
doc.setFontSize(8);
doc.setTextColor(108, 117, 125);
doc.text('This routine is a suggestion. Listen to your body and consult a professional if you experience pain.', docWidth / 2, pageHeight - 20, { align: 'center' });
doc.save('Foam-Rolling-Routine.pdf');
}