${item.status.replace('-', ' ')}
`).join('');
} else {
listContainer.innerHTML = 'Excellent! No items currently need attention.
'; } } // --- DATA HANDLING --- function handleInputChange(e) { const { category, id, field } = e.target.dataset; const item = DB[category].items.find(i => i.id === id); if (item) { item[field] = e.target.value; if (field === 'status') { e.target.className = `form-select status-${e.target.value}`; } } updateDashboard(); } // --- TAB NAVIGATION --- function updateTabDisplay(tabNum) { currentTab = tabNum; tabButtons.forEach(button => button.classList.toggle('active', parseInt(button.dataset.tab) === tabNum)); tabContents.forEach(content => content.style.display = 'none'); document.getElementById(`tab-content-${tabNum}`).style.display = 'block'; if(tabNum === 1) updateDashboard(); } // --- PDF GENERATION --- function generatePdfHtml() { let html = `Business Law Compliance Report
Generated on: ${new Date().toLocaleDateString('en-US')}
${category.title}
| Item | Status | Last Reviewed | Notes |
|---|---|---|---|
| ${item.text} | ${item.status.replace('-', ' ')} | ${item.date} | ${item.notes} |
This report is for internal informational purposes only and does not constitute legal advice. Consult with qualified legal counsel for specific compliance matters.
`; return html; } async function handlePdfDownload() { document.getElementById('pdf-content').innerHTML = generatePdfHtml(); const { jsPDF } = window.jspdf; const button = document.getElementById('downloadPdfBtn'); button.textContent = 'Generating...'; button.disabled = true; const pdfContainer = document.getElementById('pdf-container'); pdfContainer.classList.remove('invisible'); try { const canvas = await html2canvas(pdfContainer, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pageHeight = pdf.internal.pageSize.getHeight(); let heightLeft = (imgProps.height * pdfWidth) / imgProps.width; let position = 0; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, heightLeft); heightLeft -= pageHeight; while (heightLeft > 0) { position = heightLeft - ((imgProps.height * pdfWidth) / imgProps.width); pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, heightLeft); heightLeft -= pageHeight; } pdf.save('Compliance_Dashboard_Report.pdf'); } catch (error) { console.error("PDF generation failed:", error); } finally { button.textContent = 'Download Full Report as PDF'; button.disabled = false; pdfContainer.classList.add('invisible'); } } // --- INITIALIZATION & EVENT LISTENERS --- renderChecklist('corporate', 'tab-content-2'); renderChecklist('employment', 'tab-content-3'); renderChecklist('data-privacy', 'tab-content-4'); renderChecklist('contracts-ip', 'tab-content-5'); updateDashboard(); tabButtons.forEach(button => { button.addEventListener('click', () => updateTabDisplay(parseInt(button.dataset.tab))); }); document.getElementById('compliance-dashboard-container').addEventListener('change', handleInputChange); document.getElementById('downloadPdfBtn').addEventListener('click', handlePdfDownload); });