Est. Monthly Payment:${fwssl_formatCurrency(fwssl_inputData.loanMonthlyPayment)} (for ${fwssl_inputData.loanTermYears} years)
Total Repaid Over Loan Life:${fwssl_formatCurrency(fwssl_inputData.loanTotalRepayment)}
Total Interest Cost:${fwssl_formatCurrency(fwssl_inputData.loanTotalInterest)}
Key Takeaway:
Federal Work-Study provides funds you earn through work. This money does not need to be repaid and does not accrue interest, directly reducing your education costs and future debt.
Student loans provide immediate funds but must be repaid with interest, increasing the overall cost of your education and creating a future debt obligation.
`;
}
if (fwssl_domElements.pdfDownloadBtn) {
fwssl_domElements.pdfDownloadBtn.classList.remove('fwssl-hidden');
}
}
function fwssl_hexToRgb(hex) {
if (!hex || typeof hex !== 'string') return null;
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; });
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null;
}
function fwssl_generatePdf() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined' || typeof window.jspdf.jsPDF.API === 'undefined' || typeof window.jspdf.jsPDF.API.autoTable === 'undefined') {
alert("PDF generation library is not loaded. Please try again later."); return;
}
if (!fwssl_validateTab1() || !fwssl_validateTab2()) {
alert("Please ensure all inputs are correctly filled before generating PDF.");
if (!fwssl_validateTab1()) fwssl_navigateToTab('fwssl-tab1');
else if (!fwssl_validateTab2()) fwssl_navigateToTab('fwssl-tab2');
return;
}
fwssl_calculateAndDisplayComparison();
if (fwssl_domElements.resultsContainer && fwssl_domElements.resultsContainer.innerHTML.includes("fwssl-error-message")) {
alert("Cannot generate PDF due to errors in input or calculation. Please correct them."); return;
}
const ActualJsPDF = window.jspdf.jsPDF;
const doc = new ActualJsPDF();
const { amountToCompare, fwsHourlyWage, fwsHoursNeeded,
loanInterestRate, loanTermYears, loanMonthlyPayment,
loanTotalRepayment, loanTotalInterest } = fwssl_inputData;
doc.setFontSize(18);
const primaryColorRGB = fwssl_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--fwssl-primary-color').trim());
const secondaryColorRGB = fwssl_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--fwssl-secondary-color').trim());
if (primaryColorRGB) doc.setTextColor(primaryColorRGB.r, primaryColorRGB.g, primaryColorRGB.b); else doc.setTextColor(0,122,115);
doc.text("FWS vs. Student Loan Comparison", 105, 22, null, null, "center");
doc.setFontSize(12);
doc.setTextColor(51,51,51);
let startY = 35;
doc.setFontSize(11);
doc.text(`Comparison for covering an expense of: ${fwssl_formatCurrency(amountToCompare)}`, 14, startY);
startY += 10;
const tableHeadFillColor = secondaryColorRGB ? [secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b] : [0,77,64];
// Federal Work-Study Table
doc.setFontSize(13);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0,77,64);
doc.text("Scenario 1: Using Federal Work-Study", 14, startY); startY += 7;
doc.autoTable({
startY: startY, theme: 'grid', headStyles: { fillColor: tableHeadFillColor, textColor: 255, fontSize: 10},
body: [
["Assumed FWS Hourly Wage:", fwssl_formatCurrency(fwsHourlyWage)],
["Est. Hours to Work to Earn Amount:", fwssl_formatHours(fwsHoursNeeded)],
["Additional Debt Incurred:", fwssl_formatCurrency(0)],
["Interest Cost:", fwssl_formatCurrency(0)],
], margin: { left: 14, right: 14 },
styles: { fontSize: 9.5, cellPadding: 2.5 }, columnStyles: {0: {fontStyle:'bold'}}
});
startY = doc.autoTable.previous.finalY + 10;
// Student Loan Table
doc.setFontSize(13);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0,77,64);
doc.text("Scenario 2: Using a Student Loan", 14, startY); startY += 7;
doc.autoTable({
startY: startY, theme: 'grid', headStyles: { fillColor: tableHeadFillColor, textColor: 255, fontSize:10 },
body: [
["Amount Borrowed (Loan Principal):", fwssl_formatCurrency(amountToCompare)],
["Assumed Annual Loan Interest Rate:", fwssl_formatPercent(loanInterestRate)],
["Assumed Loan Term:", `${loanTermYears} years`],
["Estimated Monthly Loan Payment:", fwssl_formatCurrency(loanMonthlyPayment)],
["Total Repaid Over Loan Life:", fwssl_formatCurrency(loanTotalRepayment)],
["Total Interest Cost:", fwssl_formatCurrency(loanTotalInterest)],
], margin: { left: 14, right: 14 },
styles: { fontSize: 9.5, cellPadding: 2.5 }, columnStyles: {0: {fontStyle:'bold'}}
});
startY = doc.autoTable.previous.finalY + 12;
doc.setFontSize(10);
doc.setTextColor(51,51,51);
doc.setFont(undefined, 'bold');
doc.text("Key Takeaway:", 14, startY); startY += 6;
doc.setFont(undefined, 'normal');
doc.setFontSize(9);
const takeaway1 = "Federal Work-Study provides funds you earn through work. This money does not need to be repaid and does not accrue interest, directly reducing your education costs and future debt.";
const takeaway2 = "Student loans provide immediate funds but must be repaid with interest, increasing the overall cost of your education and creating a future debt obligation.";
const splitTakeaway1 = doc.splitTextToSize(takeaway1, doc.internal.pageSize.width - 28);
doc.text(splitTakeaway1, 14, startY);
startY += (splitTakeaway1.length * (doc.getLineHeight() / doc.internal.scaleFactor * 0.85)) + 3;
const splitTakeaway2 = doc.splitTextToSize(takeaway2, doc.internal.pageSize.width - 28);
doc.text(splitTakeaway2, 14, startY);
doc.setFontSize(9);
doc.setTextColor(120);
doc.text(`Report generated on: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`, 14, doc.internal.pageSize.height - 10);
doc.save("FWS_vs_Loan_Comparison.pdf");
}
window.fwssl_switchTab = fwssl_switchTab;
window.fwssl_navigateToTab = fwssl_navigateToTab;
window.fwssl_generatePdf = fwssl_generatePdf;