${riskDescription}
Note: This calculator is based on the Framingham Risk Score and provides an estimate for informational purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment.
`;
resultsSection.classList.remove('hidden');
};
// --- 6. PDF GENERATION ---
const handlePdfDownload = () => {
const { jsPDF } = window.jspdf;
const contentToPrint = document.getElementById('printable-content');
const buttonContainer = document.getElementById('pdf-button-container');
if (!contentToPrint) return;
buttonContainer.classList.add('hide-for-pdf');
html2canvas(contentToPrint, { scale: 2, useCORS: true }).then(canvas => {
buttonContainer.classList.remove('hide-for-pdf');
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / pdfWidth;
const calculatedHeight = canvasHeight / ratio;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, calculatedHeight);
pdf.save('Heart_Disease_Risk_Report.pdf');
}).catch(err => {
buttonContainer.classList.remove('hide-for-pdf');
showError('An error occurred while generating the PDF.');
});
};
// --- 7. EVENT LISTENERS ---
calculateBtn.addEventListener('click', calculateRisk);
downloadPdfBtn.addEventListener('click', handlePdfDownload);
});
