${recommendationsHTML}
`;
};
window.showTab = (tabName) => {
const newIndex = tabOrder.indexOf(tabName);
if (newIndex === -1) return;
if (tabName === 'results') {
calculateResults();
}
tabOrder.forEach((name, index) => {
const content = document.getElementById(`tab-content-${name}`);
const btn = document.getElementById(`tab-btn-${name}`);
if (!content || !btn) return;
if (name === tabName) {
content.classList.remove('hidden');
btn.classList.remove('tab-inactive');
btn.classList.add('tab-active');
} else {
content.classList.add('hidden');
btn.classList.remove('tab-active');
btn.classList.add('tab-inactive');
}
});
currentTabIndex = newIndex;
updateNavButtons();
};
window.navigateTabs = (direction) => {
if (direction === 'next') {
currentTabIndex = Math.min(currentTabIndex + 1, tabOrder.length - 1);
} else {
currentTabIndex = Math.max(currentTabIndex - 1, 0);
}
showTab(tabOrder[currentTabIndex]);
};
const updateNavButtons = () => {
prevBtn.disabled = currentTabIndex === 0;
nextBtn.disabled = currentTabIndex === tabOrder.length - 1;
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
window.downloadPDF = () => {
if (!lastCalculatedResults) {
alert('Please complete the assessment on the "Results" tab first.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { totalScore, assessment, description, recommendations, selected } = lastCalculatedResults;
doc.setFontSize(18);
doc.text('Histamine Intolerance Assessment Report', 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Report Date: ${new Date().toLocaleDateString()}`, 14, 30);
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.text('Your Assessment Result', 14, 45);
doc.setFontSize(12);
doc.setFont('helvetica', 'bold');
doc.text(`Score: ${totalScore} - ${assessment}`, 14, 55);
doc.setFont('helvetica', 'normal');
doc.setTextColor(80);
doc.text(description, 14, 62, { maxWidth: 180 });
let startY = 80;
if (selected.length > 0) {
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.setTextColor(0);
doc.text('Your Selected Symptoms', 14, startY);
startY += 10;
const groupedForPdf = selected.reduce((acc, symptom) => {
acc[symptom.category] = acc[symptom.category] || [];
acc[symptom.category].push(symptom.name);
return acc;
}, {});
for (const category in groupedForPdf) {
doc.setFontSize(11);
doc.setFont('helvetica', 'bold');
doc.text(category, 14, startY);
startY += 6;
doc.setFont('helvetica', 'normal');
groupedForPdf[category].forEach(name => {
doc.text(`- ${name}`, 18, startY);
startY += 6;
if (startY > 270) { doc.addPage(); startY = 20; }
});
startY += 4;
}
}
if (recommendations.length > 0) {
startY += 5;
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.text('Recommendations', 14, startY);
startY += 8;
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
recommendations.forEach(rec => {
// Simple tag removal for PDF
const cleanRec = rec.replace(/<\/?strong>/g, '');
doc.text(`• ${cleanRec}`, 18, startY, { maxWidth: 170 });
startY += 10;
if (startY > 270) { doc.addPage(); startY = 20; }
});
}
const disclaimerY = doc.internal.pageSize.height - 20;
doc.setFontSize(8);
doc.setTextColor(150);
doc.text('Disclaimer: This report is for informational purposes only and is not a substitute for professional medical advice.', 14, disclaimerY, { maxWidth: 180 });
doc.save('Histamine_Intolerance_Assessment.pdf');
};
// --- INITIALIZATION ---
renderSymptoms();
showTab('instructions');
});
