`;
});
} else {
reportHTML += `
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(); });