`;
}
function clceDownloadPDF() {
if (!clceLastCalculationData) {
alert("Please calculate the loan payments first before downloading the PDF.");
clceNavigateTab('clceResultsTab');
clceCalculateLoan();
if (!clceLastCalculationData) return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, results } = clceLastCalculationData;
const primaryColor = [0, 121, 107];
let y = 15;
doc.setFontSize(16); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Car Loan Payment Estimation for Expats", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 8;
doc.setFontSize(8); doc.setTextColor(100);
doc.text("General calculations based on inputs. Informational points are general.", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 10;
doc.setFontSize(11); doc.setTextColor(51, 51, 51);
doc.text("Loan Inputs:", 14, y); y += 7;
doc.setFontSize(10);
doc.text(` Loan Amount: $${inputs.loanAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`, 14, y); y += 6;
doc.text(` Annual Interest Rate: ${inputs.annualRate.toFixed(2)}%`, 14, y); y += 6;
let termString = `${inputs.termYears} year(s)`;
if (inputs.termMonthsExtra > 0) {
termString += `, ${inputs.termMonthsExtra} month(s)`;
}
termString += ` (Total ${inputs.totalTermMonths} months)`;
doc.text(` Loan Term: ${termString}`, 14, y); y += 10;
doc.setFontSize(11); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Estimated Payments:", 14, y); y += 7;
doc.setFontSize(10); doc.setTextColor(51, 51, 51);
doc.text(` Estimated Monthly Payment: $${results.monthlyPayment.toFixed(2)}`, 14, y); y += 6;
doc.text(` Total Principal Paid: $${results.totalPrincipal.toFixed(2)}`, 14, y); y += 6;
doc.text(` Total Interest Paid: $${results.totalInterest.toFixed(2)}`, 14, y); y += 6;
doc.setFont(undefined, 'bold');
doc.text(` Total Cost of Loan (Principal + Interest): $${results.totalCost.toFixed(2)}`, 14, y); y += 10;
doc.setFont(undefined, 'normal');
if (y > 180) { doc.addPage(); y = 20; } // Check for page break before considerations
doc.setFontSize(11); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("General Considerations for Expats Seeking Auto Loans:", 14, y); y += 6;
doc.setFontSize(9); doc.setTextColor(85, 85, 85); // #555
const considerations = [
"Credit History: Establishing credit in a new country can take time. Lenders may have specific criteria or require alternative proof of financial standing if local credit history is limited or non-transferable.",
"Residency & Visa Status: Loan terms, eligibility, and sometimes the loan duration might be influenced by your visa type, validity, and length of permitted stay.",
"Income Verification & Employment: Requirements for proving income and employment stability can vary. Be prepared for comprehensive documentation.",
"Banking Relationships: An established local bank relationship might be beneficial.",
"Down Payment: Lenders might require a larger down payment for non-residents or those with limited local credit.",
"Local Regulations & Market: Familiarize yourself with local credit laws and financing regulations."
];
considerations.forEach(item => {
const splitItem = doc.splitTextToSize(`• ${item}`, doc.internal.pageSize.getWidth() - 28 - 5); // 14 margin, 5 for bullet
doc.text(splitItem, 14, y);
y += (splitItem.length * 4) + 2; // Adjust line height
if (y > 260 && considerations.indexOf(item) < considerations.length -1) { doc.addPage(); y = 20; }
});
y += 4;
doc.setFontSize(8); doc.setFont(undefined, 'italic'); doc.setTextColor(100);
const finalNote = "This information is for general awareness only and not financial or legal advice. It's highly recommended to research specific requirements and consult directly with financial institutions in your country of residence.";
const splitFinalNote = doc.splitTextToSize(finalNote, doc.internal.pageSize.getWidth() - 28);
doc.text(splitFinalNote, 14, y);
doc.save("Car_Loan_Estimation_Expat.pdf");
}
clceSwitchTab(null, 'clceLoanDetailsTab'); // Ensure first tab is active on load
window.clceSwitchTab = clceSwitchTab;
window.clceNavigateTab = clceNavigateTab;
window.clceCalculateLoan = clceCalculateLoan;
window.clceDownloadPDF = clceDownloadPDF;
