`;
});
const resultsHTML = `
`;
resultsContainer.innerHTML = resultsHTML;
resultsContainer.classList.remove('hidden');
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
resultsContainer.scrollIntoView({ behavior: 'smooth' });
}
function downloadPdf() {
if (!planResults) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Header
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text('Mind-Gut Connection Wellness Plan', 105, 20, { align: 'center' });
doc.setFontSize(16);
doc.text(`Your Goal: ${planResults.title}`, 105, 28, { align: 'center' });
// Table of Plan
const tableData = planResults.plan.map((item, index) => [`Day ${index + 1}`, item.category, item.tip]);
doc.autoTable({
startY: 40,
head: [['Day', 'Focus Area', 'Action Step']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: [16, 185, 129] }, // emerald-500
columnStyles: { 2: { cellWidth: 100 } }
});
let finalY = doc.autoTable.previous.finalY;
// Disclaimer
if (finalY > 240) { doc.addPage(); finalY = 20; }
doc.setFontSize(12);
doc.setFont('helvetica', 'bold');
doc.setTextColor(239, 68, 68); // Red
doc.text('Important Medical Disclaimer', 14, finalY + 15);
doc.setFontSize(10);
doc.setTextColor(0, 0, 0); // Black
const disclaimerText = doc.splitTextToSize("This guide provides general wellness suggestions and is NOT a substitute for professional medical advice. Always consult a qualified healthcare professional before making significant dietary or lifestyle changes.", 180);
doc.text(disclaimerText, 14, finalY + 22);
doc.save(`Mind-Gut-Plan-${planResults.title}.pdf`);
}
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', generatePlan);
});
Your 7-Day Mind-Gut Plan
For ${planResults.title}
${planHTML}
