This report highlights potential compliance risks for ${businessName} based on your checklist answers. Items marked "No" may require further attention.
`;
for (const category in checklistData) {
const categoryRisks = [];
checklistData[category].forEach(item => {
if (checklistAnswers[item.id] === 'no') {
categoryRisks.push({
question: item.question,
recommendation: item.recommendation
});
risksFound = true;
}
});
if (categoryRisks.length > 0) {
reportHtml += `
${category}
`;
categoryRisks.forEach(risk => {
reportHtml += `
Potential Risk:
${risk.question}
Best Practice Guideline:
${risk.recommendation}
`;
});
reportHtml += `
`;
}
}
if (!risksFound) {
reportHtml += `
No Potential Risks Identified
Based on your answers, no common compliance risks were flagged. Continue to monitor your practices and consult with a legal professional for specific advice.
`;
}
document.getElementById('report-preview').innerHTML = reportHtml;
document.getElementById('download-container').classList.remove('hidden');
lucide.createIcons();
};
// --- UI & NAVIGATION ---
const updateNavButtons = () => {
prevBtn.disabled = currentTab === '1';
nextBtn.disabled = currentTab === '3';
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
window.switchTab = (tabId) => {
// Validation before leaving tab 1
if (currentTab === '1' && tabId === '2') {
const businessName = document.getElementById('businessName').value;
if (!businessName) {
alert('Please enter a business name before proceeding.');
return;
}
}
currentTab = tabId;
tabs.forEach(id => {
document.getElementById(`tab-content-${id}`).classList.toggle('hidden', id !== currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-active', id === currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-inactive', id !== currentTab);
});
if (tabId === '3') {
generateReport();
}
updateNavButtons();
};
const navigateTabs = (direction) => {
const currentIndex = tabs.indexOf(currentTab);
let nextIndex = currentIndex + direction;
if (nextIndex >= 0 && nextIndex < tabs.length) {
switchTab(tabs[nextIndex]);
}
};
// --- PDF GENERATION ---
const downloadPdf = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const businessName = document.getElementById('businessName').value || 'Your Business';
doc.setFontSize(18);
doc.text("Consumer Protection Compliance Report", 40, 60);
doc.setFontSize(12);
doc.text(`For: ${businessName}`, 40, 80);
const tableData = [];
for (const category in checklistData) {
let hasRiskInCategory = false;
checklistData[category].forEach(item => {
if (checklistAnswers[item.id] === 'no') {
if (!hasRiskInCategory) {
tableData.push([{ content: category, colSpan: 2, styles: { fontStyle: 'bold', fillColor: '#f3f4f6' } }]);
hasRiskInCategory = true;
}
tableData.push([
{ content: `Risk: ${item.question}`, styles: { fontStyle: 'bold' }},
{ content: `Guideline: ${item.recommendation}` }
]);
}
});
}
if(tableData.length > 0) {
doc.autoTable({
startY: 100,
head: [['Potential Risk Area', 'Best Practice Guideline']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: [59, 130, 246] },
didParseCell: function(data) {
if (data.cell.section === 'body' && data.cell.raw.colSpan) {
data.cell.styles.halign = 'center';
}
}
});
} else {
doc.setFontSize(14);
doc.setTextColor(34, 139, 34);
doc.text("No Potential Risks Identified", 40, 120);
doc.setTextColor(0, 0, 0);
doc.setFontSize(11);
doc.text("Based on your checklist answers, no common compliance risks were flagged.", 40, 140);
}
doc.save(`Compliance_Report_${businessName.replace(/\s/g, '_')}.pdf`);
};
// --- EVENT LISTENERS & INITIAL SETUP ---
prevBtn.addEventListener('click', () => navigateTabs(-1));
nextBtn.addEventListener('click', () => navigateTabs(1));
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
// Initial setup
generateChecklist();
updateNavButtons();
lucide.createIcons();
});