`;
}
// --- TAB LOGIC ---
window.changeTab = function(tabName) {
const tabs = ['calculator', 'guides', 'about'];
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 protection plan first to generate a report.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
let yPos = 20;
const { skinType, spf, uvIndex, finalRecommendation, reapplicationReason, adjustedMinsToBurnNoSPF } = lastResult;
// Title
doc.setFontSize(16);
doc.setFont('helvetica', 'bold');
doc.text('My Sun Protection 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 Results', 15, yPos);
yPos += 10;
const finalHours = Math.floor(finalRecommendation / 60);
const finalMinutes = finalRecommendation % 60;
const timeString = `${finalHours > 0 ? `${finalHours}h ` : ''}${finalMinutes > 0 ? `${finalMinutes}m` : ''}`.trim();
doc.setFontSize(11);
doc.setFont('helvetica', 'bold');
doc.text('Recommended Reapplication Time:', 15, yPos);
doc.setFontSize(22);
doc.text(timeString, 100, yPos);
yPos += 10;
doc.setFontSize(10);
doc.setFont('helvetica', 'italic');
doc.text(doc.splitTextToSize(reapplicationReason, 180), 15, yPos);
yPos += 15;
// Inputs Summary Table
doc.autoTable({
startY: yPos,
head: [['Your Inputs', 'Value']],
body: [
['Skin Type', `Type ${skinType}`],
['Sunscreen SPF', spf],
['UV Index', `${uvIndex} (${uvIndexLabels[uvIndex]})`],
['Est. time to burn without SPF', `~${adjustedMinsToBurnNoSPF} minutes`]
],
theme: 'grid',
headStyles: { fillColor: [41, 128, 185] },
});
yPos = doc.autoTable.previous.finalY + 15;
// General Advice
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.text('General Sun Safety Advice', 15, yPos);
yPos += 7;
doc.setFontSize(10);
doc.setFont('helvetica', 'normal');
const advice = [
"Apply sunscreen 15-30 minutes before sun exposure.",
"Use about one ounce (a shot glass full) to cover your entire body.",
"Don't forget areas like the tops of your ears, feet, and neck.",
"Wear protective clothing, a wide-brimmed hat, and UV-blocking sunglasses.",
"Seek shade, especially during peak sun hours (10 a.m. to 4 p.m.).",
"This calculator is an educational estimate. Always prioritize safe sun practices."
];
advice.forEach(item => {
doc.text(`• ${item}`, 20, yPos);
yPos += 6;
});
doc.save(`My-Sun-Protection-Plan-${new Date().toISOString().slice(0,10)}.pdf`);
};
// --- INITIAL LOAD ---
changeTab('calculator');
});