`;
reportContainer.innerHTML = html;
showTab(3);
}
function downloadPdf() {
if (!appData.checklistResults) { alert('Please generate a report first.'); return; }
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(18);
doc.text("Consumer Protection Compliance Risk Report", 105, 20, { align: 'center' });
doc.setFontSize(11);
doc.text(`For: ${appData.companyName}`, 105, 28, { align: 'center' });
// Recalculate for PDF
let riskScore = 0;
if (appData.industry === 'leadgen') riskScore += 20;
if (appData.industry === 'saas' || appData.industry === 'ecommerce') riskScore += 15;
if (appData.subscription === '1') riskScore += 25;
if (appData.children === '1') riskScore += 40;
const highRiskItems = [];
appData.checklistResults.forEach(item => { if (item.isNonCompliant) { riskScore += item.weight; highRiskItems.push(item); } });
riskScore = Math.min(Math.round(riskScore * 0.8), 150);
let riskLevel;
if (riskScore >= 90) riskLevel = 'Very High'; else if (riskScore >= 70) riskLevel = 'High'; else if (riskScore >= 40) riskLevel = 'Moderate'; else riskLevel = 'Low';
doc.setFontSize(12);
doc.text(`Predicted Risk Level: ${riskLevel} (Score: ${riskScore})`, 14, 45);
const tableBody = highRiskItems.map(r => [r.category, r.text, r.recommendation]);
if (highRiskItems.length > 0) {
doc.autoTable({
startY: 55,
head: [['Category', 'Identified Risk Factor', 'Recommendation']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: [79, 70, 229] },
columnStyles: { 2: { cellWidth: 80 } }
});
} else {
doc.text("No significant risk factors identified based on responses.", 14, 60);
}
doc.save(`Consumer-Protection-Risk-Report-${appData.companyName.replace(/\s/g, '_')}.pdf`);
}
// --- Event Listeners ---
nextBtn.addEventListener('click', () => {
if (!validateTab(currentTab)) return;
saveTabData();
if (currentTab < totalTabs - 1) {
showTab(currentTab + 1);
} else {
generateReport();
}
});
prevBtn.addEventListener('click', () => {
if (currentTab > 1) {
showTab(currentTab - 1);
}
});
getEl('download-pdf-btn').addEventListener('click', downloadPdf);
// --- Initialization ---
populateChecklist();
updateNavigation();
});