`;
}
function rvlcDownloadPDF() {
if (!rvlcLastCalculationData) {
alert("Please calculate the loan payments first before downloading the PDF.");
// Optionally, trigger calculation if inputs valid
// rvlcNavigateTab('rvlcResultsTab');
// rvlcCalculateLoan();
// if (!rvlcLastCalculationData) return;
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, results } = rvlcLastCalculationData;
const primaryColor = [0, 121, 107];
let y = 15;
doc.setFontSize(16); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Recreational Vehicle (RV) Loan Estimation", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 8;
doc.setFontSize(8); doc.setTextColor(100);
doc.text("General calculations based on inputs. Advisory notes are general.", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 10;
doc.setFontSize(11); doc.setTextColor(51, 51, 51);
doc.text("RV Loan Inputs:", 14, y); y += 7;
doc.setFontSize(10);
doc.text(` RV 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 Loan 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; }
doc.setFontSize(11); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Understanding Your RV Loan Estimate:", 14, y); y += 6;
doc.setFontSize(9); doc.setTextColor(85, 85, 85);
const advisoryNotes = [
"RV Loan Variables: Interest rates and terms for RVs vary based on RV type (motorhome, trailer, etc.), new/used status, loan amount, down payment, and credit profile. Terms can be long (10-20 years).",
"Shop Around: Compare offers from multiple lenders (banks, credit unions, RV-specific financers).",
"Additional Costs of Ownership: Remember other costs like insurance, registration, taxes, maintenance, storage, and site fees.",
"Loan Agreement is Key: Thoroughly review your specific loan agreement for all terms before signing."
];
advisoryNotes.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;
if (y > 260 && advisoryNotes.indexOf(item) < advisoryNotes.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 and estimation purposes only and does not constitute financial advice.";
const splitFinalNote = doc.splitTextToSize(finalNote, doc.internal.pageSize.getWidth() - 28);
doc.text(splitFinalNote, 14, y);
doc.save("RV_Loan_Estimation.pdf");
}
rvlcSwitchTab(null, 'rvlcLoanDetailsTab'); // Ensure first tab is active on load
window.rvlcSwitchTab = rvlcSwitchTab;
window.rvlcNavigateTab = rvlcNavigateTab;
window.rvlcCalculateLoan = rvlcCalculateLoan;
window.rvlcDownloadPDF = rvlcDownloadPDF;
