${comparisonOutputDiv.innerHTML}
`;
// Temporarily hide the main tool container to avoid layout issues during PDF generation
toolContainer.style.display = 'none';
html2pdf().from(pdfContent).set({
margin: [20, 20, 20, 20], // Top, Left, Bottom, Right
filename: 'Investment_Fund_Structure_Comparison.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'landscape' } /* Landscape for wider tables */
}).save().then(() => {
// Restore visibility of the main tool container after PDF generation is complete
toolContainer.style.display = 'flex';
pdfContent.remove(); // Clean up temporary element
}).catch(error => {
console.error("Error generating PDF:", error);
showCustomModal('PDF Generation Error', 'There was an issue generating the PDF. Please try again.');
toolContainer.style.display = 'flex';
pdfContent.remove();
});
}
// --- Event Listeners ---
if (compareButton) {
compareButton.addEventListener('click', generateComparisonTable);
}
if (clearSelectionButton) {
clearSelectionButton.addEventListener('click', clearSelection);
}
if (downloadPdfButton) {
downloadPdfButton.addEventListener('click', downloadPDF);
}
// Custom modal close button
if (modalCloseButton) {
modalCloseButton.addEventListener('click', hideCustomModal);
}
// Close modal if clicking outside (on overlay)
if (customModalOverlay) {
customModalOverlay.addEventListener('click', (e) => {
if (e.target === customModalOverlay) {
hideCustomModal();
}
});
}
// --- Initial Setup ---
populateCheckboxes(); // Populate checkboxes on load
});