`).join('');
};
outputDiv.innerHTML = `
`;
}
function downloadPlanPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const docWidth = doc.internal.pageSize.getWidth();
const margin = 40;
let currentY = margin;
// Header
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.setTextColor(79, 70, 229);
doc.text('Personalized Skin Care Plan', margin, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(108, 117, 125);
doc.text(`Plan 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 += 25;
};
// Profile Section
addSectionHeader('Your Skin Profile');
doc.setFontSize(12);
doc.text(`Skin Type:`, margin, currentY);
doc.setFont('helvetica', 'bold');
doc.text(lastAnalysis.skinType, margin + 150, currentY);
currentY += 20;
doc.setFont('helvetica', 'normal');
doc.text(`Primary Concerns:`, margin, currentY);
doc.setFont('helvetica', 'bold');
doc.text(lastAnalysis.concerns.join(', ') || 'None specified', margin + 150, currentY);
currentY += 40;
// AM Routine
addSectionHeader('☀️ Morning (AM) Routine');
doc.autoTable({
startY: currentY,
head: [['Step', 'Product Type', 'Purpose']],
body: lastAnalysis.amRoutine.map((p, i) => [i + 1, p, db.products[p]]),
theme: 'striped',
headStyles: { fillColor: [79, 70, 229] },
styles: { font: 'helvetica', fontSize: 9 },
columnStyles: { 2: { cellWidth: 250 } }
});
currentY = doc.autoTable.previous.finalY + 30;
// PM Routine
addSectionHeader('🌙 Evening (PM) Routine');
doc.autoTable({
startY: currentY,
head: [['Step', 'Product Type', 'Purpose']],
body: lastAnalysis.pmRoutine.map((p, i) => [i + 1, p, db.products[p]]),
theme: 'striped',
headStyles: { fillColor: [55, 48, 163] },
styles: { font: 'helvetica', fontSize: 9 },
columnStyles: { 2: { cellWidth: 250 } }
});
// Footer
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFontSize(8);
doc.setTextColor(108, 117, 125);
doc.text('This plan is a guideline. Patch test new products and consult a dermatologist for medical advice.', docWidth / 2, pageHeight - 20, { align: 'center' });
doc.save('My-Skin-Care-Plan.pdf');
}
Your Skin Analysis
${analysis.skinType}
${analysis.concerns.length > 0 ? `Primary Concerns: ${analysis.concerns.join(', ')}
` : ''}☀️ Morning (AM) Routine
- ${createRoutineList(analysis.amRoutine)}
🌙 Evening (PM) Routine
- ${createRoutineList(analysis.pmRoutine)}
