`).join('')}
`;
pdfContentArea.style.display = 'block';
pdfContentArea.style.position = 'absolute';
pdfContentArea.style.left = '-9999px';
pdfContentArea.style.width = '800px';
try {
const canvas = await html2canvas(pdfContentArea, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgHeight = canvas.height * pdfWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight);
pdf.save(`SMART-Goals-Report-${new Date().toISOString().split('T')[0]}.pdf`);
} catch (error) {
console.error("Failed to generate PDF:", error);
alert("Sorry, there was an error creating the PDF file.");
} finally {
pdfContentArea.style.display = 'none';
}
}
// --- Event Listeners ---
addGoalBtn.addEventListener('click', () => openModal());
cancelBtn.addEventListener('click', closeModal);
goalForm.addEventListener('submit', handleFormSubmit);
goalsList.addEventListener('click', handleListClick);
downloadPdfBtn.addEventListener('click', generatePdf);
// --- Initial Load ---
renderGoals();
});
