`;
// Animate the glasses filling up
setTimeout(() => {
document.querySelectorAll('.water-glass').forEach(glass => {
glass.classList.add('filled');
});
}, 100);
}
// --- TAB LOGIC ---
window.changeTab = function(tabName) {
const tabs = ['calculator', 'guide'];
tabs.forEach(tab => {
document.getElementById(`${tab}-tab`).style.display = 'none';
const btn = document.getElementById(`tab-btn-${tab}`);
btn.classList.remove('active', 'border-blue-500', 'text-blue-600');
btn.classList.add('text-slate-600');
});
document.getElementById(`${tabName}-tab`).style.display = 'block';
const activeBtn = document.getElementById(`tab-btn-${tabName}`);
activeBtn.classList.add('active', 'border-blue-500', 'text-blue-600');
activeBtn.classList.remove('text-slate-600');
};
// --- PDF DOWNLOAD ---
window.downloadPDF = function() {
if (!lastResult) {
alert("Please calculate your water intake first to generate a report.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
let yPos = 20;
const { weight, activity, totalIntakeOz, totalIntakeLiters, glasses } = lastResult;
// Title
doc.setFontSize(16);
doc.setFont('helvetica', 'bold');
doc.text('My Daily Hydration & Oral Health Plan', 105, 15, { align: 'center' });
doc.setFontSize(10);
doc.setFont('helvetica', 'normal');
doc.text(`Report Generated: ${new Date().toLocaleDateString()}`, 105, 20, { align: 'center' });
yPos = 30;
// Results
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.text('Your Personalized Hydration Goal', 15, yPos);
yPos += 10;
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
doc.text(`Based on a weight of ${weight} lbs and a ${activity.split(' ')[0].toLowerCase()} activity level, your recommended daily water intake is:`, 15, yPos, { maxWidth: 180 });
yPos += 15;
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text(`${totalIntakeOz} oz`, 105, yPos, { align: 'center' });
yPos += 8;
doc.setFontSize(12);
doc.setFont('helvetica', 'normal');
doc.text(`(${totalIntakeLiters} Liters / approximately ${glasses} glasses)`, 105, yPos, { align: 'center' });
yPos += 15;
// Oral Health Connection
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.text('Why This Matters for Your Oral Health', 15, yPos);
yPos += 7;
doc.setFontSize(10);
doc.setFont('helvetica', 'normal');
const guideText = [
"Keeps Your Mouth Clean: Water washes away food particles and sugars that cause cavities.",
"Fights Dry Mouth: Proper hydration ensures you produce enough saliva, your mouth's primary defense against decay.",
"Strengthens Teeth: Fluoridated water helps rebuild and strengthen tooth enamel.",
"Combats Bad Breath: Staying hydrated prevents a dry environment where odor-causing bacteria thrive."
];
guideText.forEach(item => {
doc.text(`• ${item}`, 20, yPos, { maxWidth: 170 });
yPos += 8;
});
// Disclaimer
doc.setFontSize(8);
doc.setFont('helvetica', 'italic');
doc.text("Disclaimer: This is an educational tool providing a general estimate. Individual hydration needs can vary. Consult with a healthcare professional for personalized medical advice.", 15, doc.internal.pageSize.height - 15, { maxWidth: 180 });
doc.save(`My-Hydration-Plan-${new Date().toISOString().slice(0,10)}.pdf`);
};
// --- INITIAL LOAD ---
changeTab('calculator');
});
