`;
});
formHTML += ``;
});
formContainer.innerHTML = formHTML;
};
// Function to switch tabs
const showTab = (tabNumber) => {
document.querySelectorAll('.tab-pane').forEach(pane => pane.classList.add('hidden'));
const newTab = getElement(`tab-${tabNumber}`);
if (newTab) newTab.classList.remove('hidden');
document.querySelectorAll('.tab-btn').forEach(btn => {
if (btn.dataset.tab === `tab-${tabNumber}`) {
btn.classList.replace('inactive', 'active');
} else {
btn.classList.replace('active', 'inactive');
}
});
currentTab = tabNumber;
updateNavigation();
};
// Function to update navigation buttons and indicator
const updateNavigation = () => {
if (!prevBtn || !nextBtn || !stepIndicator) return;
prevBtn.disabled = currentTab === 1;
if (currentTab === totalTabs) {
nextBtn.classList.add('hidden');
} else {
nextBtn.classList.remove('hidden');
}
if (currentTab === 2) {
nextBtn.textContent = 'View Report';
} else {
nextBtn.textContent = 'Next';
}
stepIndicator.textContent = `Step ${currentTab} of ${totalTabs}`;
};
// Function to calculate score and generate the report
const generateReport = () => {
if (!formContainer) return;
const formData = new FormData(formContainer);
let score = 0;
let maxScore = 0;
const recommendations = [];
let questionIndex = 0;
Object.values(checklistData).flat().forEach(item => {
const fieldName = `q_${Math.floor(questionIndex / checklistData[Object.keys(checklistData)[0]].length)}_${questionIndex % checklistData[Object.keys(checklistData)[0]].length}`;
let answerValue = -1;
let answerText = 'Not Answered';
const fieldNodeList = formContainer.querySelectorAll(`input[name="${fieldName}"]`);
if(fieldNodeList && fieldNodeList.length > 0) {
const checkedRadio = Array.from(fieldNodeList).find(r => r.checked);
if(checkedRadio) {
answerValue = parseInt(checkedRadio.value, 10);
score += answerValue;
if(answerValue !== 1) { // N/A doesn't count towards max score
maxScore += 2;
}
if(answerValue === 0) { // If 'No'
recommendations.push({ q: item.q, r: item.r, a: 'No' });
}
if(answerValue === 2) {
recommendations.push({ q: item.q, r: '', a: 'Yes' });
}
if(answerValue === 1) {
recommendations.push({ q: item.q, r: '', a: 'N/A' });
}
} else {
// If not answered, handle it. For now, just logging.
recommendations.push({ q: item.q, r: 'This question was not answered.', a: 'Not Answered' });
}
}
questionIndex++;
});
const percentage = maxScore > 0 ? Math.round((score / maxScore) * 100) : 100;
let scoreClass, summaryTitle, summaryText;
if (percentage >= 85) {
scoreClass = 'compliant';
summaryTitle = 'Excellent (Likely Compliant)';
summaryText = 'Your responses indicate a strong and well-maintained identity theft prevention program. Continue to monitor and update your program regularly.';
} else if (percentage >= 60) {
scoreClass = 'needs-improvement';
summaryTitle = 'Needs Improvement';
summaryText = 'Your responses suggest some components of an identity theft prevention program are in place, but there are critical gaps. Please review the recommendations below carefully.';
} else {
scoreClass = 'high-risk';
summaryTitle = 'High Risk (Likely Non-Compliant)';
summaryText = 'Your responses indicate significant deficiencies in your identity theft prevention program. Immediate action is required to address the risks identified in the recommendations below.';
}
const reportContentEl = getElement('report-content');
if (!reportContentEl) return;
let reportHTML = `
Compliance Report
${summaryTitle}
${percentage}%
${summaryText}
Detailed Recommendations
`;
const itemsToRecommend = recommendations.filter(rec => rec.a === 'No');
if (itemsToRecommend.length > 0) {
itemsToRecommend.forEach(rec => {
reportHTML += `
`;
});
} else {
reportHTML += `
${rec.q}
Recommendation: ${rec.r}
No critical issues found based on your answers. Well done!
`; } reportHTML += `Disclaimer: This tool is for informational purposes only and does not constitute legal advice. Consult with a qualified professional for specific compliance guidance.
`; reportContentEl.innerHTML = reportHTML; window.complianceDataForPdf = { percentage, summaryTitle, summaryText, recommendations }; showTab(3); }; // Function to generate and download the PDF const handlePdfDownload = () => { const { jsPDF } = window.jspdf; if (!window.complianceDataForPdf) { alert('Please generate a report first.'); return; } const { percentage, summaryTitle, summaryText, recommendations } = window.complianceDataForPdf; const companyName = getElement('companyName')?.value || 'N/A'; const industryType = getElement('industryType')?.value || 'N/A'; const doc = new jsPDF(); // Add Header doc.setFontSize(20); doc.setFont('helvetica', 'bold'); doc.text("Identity Theft Protection Compliance Report", 105, 20, { align: 'center' }); doc.setFontSize(12); doc.setFont('helvetica', 'normal'); doc.text(`Date: ${new Date().toLocaleDateString()}`, 105, 28, { align: 'center' }); // Company Info doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.text("Company Information", 14, 45); doc.autoTable({ startY: 50, head: [['Company Name', 'Industry']], body: [[companyName, industryType]], theme: 'striped', headStyles: { fillColor: [41, 128, 185] } }); // Summary doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.text("Compliance Summary", 14, doc.autoTable.previous.finalY + 15); doc.autoTable({ startY: doc.autoTable.previous.finalY + 20, head: [['Score', 'Status', 'Summary']], body: [[`${percentage}%`, summaryTitle, summaryText]], theme: 'striped', headStyles: { fillColor: [41, 128, 185] } }); // Detailed Checklist doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.text("Checklist Details & Recommendations", 14, doc.autoTable.previous.finalY + 15); const tableBody = recommendations.map(rec => { return [rec.q, rec.a, rec.r]; }); doc.autoTable({ startY: doc.autoTable.previous.finalY + 20, head: [['Question', 'Your Answer', 'Recommendation (if applicable)']], body: tableBody, theme: 'grid', headStyles: { fillColor: [41, 128, 185] }, columnStyles: { 0: { cellWidth: 80 }, 1: { cellWidth: 25 }, 2: { cellWidth: 'auto' } }, didParseCell: function (data) { if (data.row.section === 'body' && data.column.index === 1) { if (data.cell.raw === 'No') { data.cell.styles.textColor = [231, 76, 60]; // Red data.cell.styles.fontStyle = 'bold'; } else if (data.cell.raw === 'Yes') { data.cell.styles.textColor = [39, 174, 96]; // Green } } } }); // Disclaimer doc.setFontSize(8); doc.setTextColor(150); doc.text("Disclaimer: This tool is for informational purposes only and does not constitute legal advice.", 105, doc.internal.pageSize.height - 10, { align: 'center' }); doc.save(`Compliance-Report-${companyName.replace(/\s/g, '_') || 'General'}.pdf`); }; // SECTION: Event Listeners if (nextBtn) { nextBtn.addEventListener('click', () => { if (currentTab < 2) { showTab(currentTab + 1); } else if (currentTab === 2) { if(formContainer && formContainer.checkValidity()){ generateReport(); } else { alert('Please answer all questions before proceeding.'); formContainer.reportValidity(); } } }); } if (prevBtn) { prevBtn.addEventListener('click', () => { if (currentTab > 1) { showTab(currentTab - 1); } }); } document.querySelectorAll('.tab-btn').forEach(button => { button.addEventListener('click', () => { const tabNumber = parseInt(button.dataset.tab.split('-')[1]); // Only allow navigation to previous tabs or the immediate next tab. // Report tab can only be accessed by "View Report" button if (tabNumber < currentTab || tabNumber === (currentTab + 1) && currentTab < 2) { showTab(tabNumber); } else if (tabNumber === 2 && currentTab === 3) { // Allow going back to checklist from report showTab(tabNumber); } }); }); if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', handlePdfDownload); } // SECTION: Initial Setup buildChecklistForm(); updateNavigation(); });