`;
impactHTML += `
`;
impactHTML += `
`; // end grid
impactHTML += ``;
impactDisplayArea.innerHTML = impactHTML;
// Update Summary Tab
let summaryHTML = `Margin Loan Rates (Brokerage)
Illustrative Rate: ${currentImpactData.marginRate.rate}
Impact: ${currentImpactData.marginRate.impact}
Summary for: ${currentImpactData.name}
`; summaryHTML += `Based on your selected credit score range, you may find the following general conditions when seeking financing for investments:
- `;
summaryHTML += `
- Mortgages: Typically, you might expect rates around ${currentImpactData.mortgage.rate}. ${currentImpactData.mortgage.impact.split('.')[0]}. `; // First sentence of impact summaryHTML += `
- Business Loans: Access is generally ${currentImpactData.businessLoan.access.toLowerCase()} with ${currentImpactData.businessLoan.terms.toLowerCase()}. `; summaryHTML += `
- Margin Loans: Expect ${currentImpactData.marginRate.rate.toLowerCase()} from brokers. `; summaryHTML += `
Overall: ${currentImpactData.general}
`; summaryContentArea.innerHTML = summaryHTML; if(downloadPdfBtn) downloadPdfBtn.disabled = false; if(pdfButtonContainer) pdfButtonContainer.style.display = 'block'; // Ensure PDF button container is visible // Automatically switch to the impacts tab const impactsTabIndex = Array.from(tabButtons).findIndex(btn => btn.dataset.tabTarget === '#csiioTabImpacts'); if (impactsTabIndex !== -1) { showTab(impactsTabIndex); } } if (viewImpactBtn) { viewImpactBtn.addEventListener('click', displayImpacts); } // --- PDF Download --- function loadJsPdfIfNeeded(callback) { if (jsPdfLoaded) { if (callback) callback(); return; } const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js'; script.onload = () => { jsPdfLoaded = true; console.log("jsPDF loaded dynamically."); if (callback) callback(); }; script.onerror = () => { console.error("Failed to load jsPDF."); alert("Error: Could not load PDF library."); }; document.head.appendChild(script); } function downloadReportAsPdf() { if (!jsPdfLoaded) { alert("PDF library not loaded."); return; } if (!currentImpactData) { alert("No impact data to download. Please view impacts first."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ unit: 'pt', format: 'a4' }); const data = currentImpactData; const pageMargin = 40; const pageWidth = doc.internal.pageSize.getWidth() - 2 * pageMargin; let y = pageMargin; function addMainTitle(text) { doc.setFontSize(18); doc.setFont(undefined, 'bold'); doc.setTextColor(44, 62, 80); // Primary doc.text(text, doc.internal.pageSize.getWidth() / 2, y, { align: 'center' }); y += 35; } function addSectionTitle(text) { if (y > doc.internal.pageSize.getHeight() - 70) { doc.addPage(); y = pageMargin; } doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.setTextColor(52, 152, 219); // Secondary doc.text(text, pageMargin, y); y += 25; } function addSubSectionTitle(text) { if (y > doc.internal.pageSize.getHeight() - 50) { doc.addPage(); y = pageMargin; } doc.setFontSize(11); doc.setFont(undefined, 'bold'); doc.setTextColor(44, 62, 80); // Primary doc.text(text, pageMargin, y); y += 18; } function addParagraph(text, indent = 0) { if (y > doc.internal.pageSize.getHeight() - 40) { doc.addPage(); y = pageMargin; } doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.setTextColor(52,73,94); const splitText = doc.splitTextToSize(text, pageWidth - indent); doc.text(splitText, pageMargin + indent, y); y += (doc.getTextDimensions(splitText).h) + 8; } function addListItem(text) { if (y > doc.internal.pageSize.getHeight() - 35) { doc.addPage(); y = pageMargin; } doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.setTextColor(52,73,94); const splitText = doc.splitTextToSize(`• ${text}`, pageWidth - 15); doc.text(splitText, pageMargin + 15, y); y += (doc.getTextDimensions(splitText).h) + 4; } function addDisclaimer(text) { if (y > doc.internal.pageSize.getHeight() - 60) { doc.addPage(); y = pageMargin; } doc.setFontSize(8.5); doc.setFont(undefined, 'italic'); doc.setTextColor(108, 117, 125); const splitText = doc.splitTextToSize(text, pageWidth); doc.setFillColor(236,240,241); doc.rect(pageMargin -5, y - (doc.getTextDimensions(splitText).h / 2) - 2 , pageWidth + 10, doc.getTextDimensions(splitText).h + 10, 'F'); doc.text(splitText, pageMargin, y); y += (doc.getTextDimensions(splitText).h) + 15; } addMainTitle("Credit Score Impact Assessment"); addParagraph(`Report Generated: ${new Date().toLocaleString()}`); addParagraph(`Selected Credit Score Range: ${data.name}`); y += 10; addSectionTitle("Potential Impact on Investment Opportunities"); addSubSectionTitle("Mortgage Rates (Real Estate Investment)"); addParagraph(`Illustrative Rate: ${data.mortgage.rate}`); addParagraph(`Impact: ${data.mortgage.impact}`); y += 5; addSubSectionTitle("Business Loan Access & Terms"); addParagraph(`Access Level: ${data.businessLoan.access}`); addParagraph(`Illustrative Terms: ${data.businessLoan.terms}`); addParagraph(`Impact: ${data.businessLoan.impact}`); y += 5; addSubSectionTitle("Margin Loan Rates (Brokerage)"); addParagraph(`Illustrative Rate: ${data.marginRate.rate}`); addParagraph(`Impact: ${data.marginRate.impact}`); y += 10; addSectionTitle("General Outlook"); addParagraph(data.general); y += 10; addSectionTitle("Key Considerations"); const considerations = [ "Credit scores are dynamic and can change based on your financial behavior.", "Lenders and institutions consider your overall financial profile, not just the score (e.g., income, debt-to-income ratio, down payment).", "Terms and rates can vary significantly between providers. Always shop around and compare offers.", "Ensure your credit report is accurate and dispute any errors promptly.", "Building and maintaining good credit is a long-term strategy that can provide significant financial benefits and opportunities." ]; considerations.forEach(item => addListItem(item)); y += 15; addDisclaimer("This tool provides illustrative examples for educational purposes only and does not constitute financial advice. Actual interest rates, loan terms, and investment opportunities will vary based on individual circumstances, market conditions, and lender/provider criteria. Always consult with qualified financial and legal professionals before making any investment or financial decisions."); const pageCount = doc.internal.getNumberOfPages(); for (let i = 1; i <= pageCount; i++) { doc.setPage(i); doc.setFontSize(8); doc.setTextColor(150); doc.text(`Page ${i} of ${pageCount} - Credit Score Impact Tool`, pageMargin, doc.internal.pageSize.getHeight() - 20); } doc.save('Credit_Score_Impact_Assessment.pdf'); } if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', () => loadJsPdfIfNeeded(downloadReportAsPdf)); } // --- Initialization --- showTab(0); if (downloadPdfBtn) downloadPdfBtn.disabled = true; if (pdfButtonContainer) pdfButtonContainer.style.display = 'block'; // Keep container visible loadJsPdfIfNeeded(); });