${weights[key]}%
`);
});
weightsForm.insertAdjacentHTML('beforeend', `Total: 100%
`);
// Lists
document.getElementById('customer-list').innerHTML = customers.map(c => `${c.name}
`).join('');
document.getElementById('product-list').innerHTML = products.map(p => `${p.name}
`).join('');
// Customer Select Dropdown
customerSelect.innerHTML = customers.map(c => ``).join('');
}
// --- EVENT HANDLERS ---
customerSelect.addEventListener('change', renderDashboard);
weightsForm.addEventListener('input', (e) => {
if (e.target.classList.contains('weight-input')) {
const key = e.target.dataset.key;
weights[key] = parseInt(e.target.value);
e.target.nextElementSibling.textContent = `${weights[key]}%`;
const total = Object.values(weights).reduce((a, b) => a + b, 0);
const totalEl = document.getElementById('total-weight');
totalEl.textContent = `${total}%`;
totalEl.style.color = total !== 100 ? '#ef4444' : '#16a34a';
renderDashboard();
}
});
downloadPdfBtn.addEventListener('click', generatePdf);
// --- TABS & NAVIGATION ---
window.switchTab = (tabName) => { currentTab = tabName; Object.values(tabBtns).forEach(b=>b.classList.replace('tab-active', 'tab-inactive')); Object.values(tabContents).forEach(c=>c.style.display='none'); tabBtns[tabName].classList.replace('tab-inactive', 'tab-active'); tabContents[tabName].style.display = 'block'; };
window.navigateTabs = (dir) => { if (dir==='next' && currentTab==='dashboard') switchTab('config'); else if (dir==='prev' && currentTab==='config') switchTab('dashboard'); };
// --- PDF GENERATION ---
async function generatePdf() {
const { jsPDF } = window.jspdf;
const pdfReportElement = document.getElementById('pdf-report');
const recommendations = generateRecommendations();
const customer = customers.find(c => c.id === parseInt(customerSelect.value));
document.getElementById('pdf-date').textContent = new Date().toLocaleDateString('en-US');
document.getElementById('pdf-customer-name').textContent = customer.name;
document.getElementById('pdf-preferences-summary').innerHTML = `Preferences: Target Price: ${formatUSD(customer.targetPrice)}, Max Price: ${formatUSD(customer.maxPrice)}, Essential Features: ${customer.essentialFeatures.join(', ')}
`; const pdfTableBody = document.getElementById('pdf-table-body'); pdfTableBody.innerHTML = ''; recommendations.slice(0, 5).forEach((rec, index) => { pdfTableBody.insertAdjacentHTML('beforeend', `