`;
}
selectionContainer.innerHTML += `
`;
}
}
function renderDashboard() {
if (!summaryList || !totalCostEl) return;
let totalCost = 0;
summaryList.innerHTML = '';
Object.keys(userSelections).forEach(category => {
if (category === '401k_contribution') return;
const selectedPlanId = userSelections[category];
if (selectedPlanId && selectedPlanId !== 'none') {
const planDetails = planData[category].plans.find(p => p.id === selectedPlanId);
if (planDetails) {
totalCost += planDetails.cost;
summaryList.innerHTML += `
${planData[category].title} - ${planDetails.name}
$${planDetails.cost.toFixed(2)}
`;
}
}
});
if (userSelections['401k_contribution'] > 0) {
summaryList.innerHTML += `
401(k) Contribution
${userSelections['401k_contribution']}% of Pay
`;
}
if (summaryList.innerHTML === '') {
summaryList.innerHTML = `
${categoryData.title}
${contentHTML}Make selections in the 'Plan Selection' tab.
`;
}
totalCostEl.textContent = `$${totalCost.toFixed(2)}`;
}
// --- EVENT HANDLERS --- //
selectionContainer.addEventListener('change', (e) => {
if (e.target.type === 'radio') {
const category = e.target.name;
userSelections[category] = e.target.value;
renderPlanSelection(); // Re-render to update 'selected' class
renderDashboard();
} else if (e.target.id === 'bed-401k-slider') {
const value = parseFloat(e.target.value);
userSelections['401k_contribution'] = value;
document.getElementById('bed-401k-output').textContent = `${value}%`;
renderDashboard();
}
});
pdfDownloadBtn.addEventListener('click', async () => {
const { jsPDF } = window.jspdf;
const pdfOutput = document.getElementById('bed-pdf-output');
const dashboardContent = document.getElementById('bed-dashboard-content-for-pdf');
if (!pdfOutput || !dashboardContent || !window.html2canvas || !jsPDF) return;
// Clone dashboard content into the hidden PDF container for clean rendering
pdfOutput.innerHTML = `