`;
});
html += '
';
dashboard.innerHTML = html;
}
}
function downloadPdf() {
const { jsPDF } = window.jspdf;
if (!jsPDF || !jsPDF.API.autoTable) {
alert("PDF generation library not loaded.");
return;
}
pdfDownloadButton.textContent = 'Generating...';
pdfDownloadButton.disabled = true;
try {
const doc = new jsPDF();
let potentialViolations = [];
for (const category in questions) {
questions[category].forEach(q => {
if (state.answers[category][q.id] === 'yes') {
potentialViolations.push([
category.charAt(0).toUpperCase() + category.slice(1),
q.violation,
q.text
]);
}
});
}
doc.setFontSize(20);
doc.text("Labor Law Violation Analysis Report", 105, 20, { align: 'center' });
doc.setFontSize(12);
doc.text(`Report Date: ${new Date().toLocaleDateString('en-US')}`, 15, 30);
doc.setFontSize(10);
doc.setTextColor(100);
const disclaimer = "Disclaimer: This report is for informational purposes only and is not legal advice. It is based on user-provided answers to general questions. Consult an attorney for legal guidance.";
doc.text(disclaimer, 105, 40, { align: 'center', maxWidth: 180 });
doc.setTextColor(0);
if (potentialViolations.length > 0) {
doc.autoTable({
startY: 55,
head: [['Category', 'Potential Violation', 'Related Question']],
body: potentialViolations,
theme: 'striped',
headStyles: { fillColor: [220, 38, 38] } // Red header
});
} else {
doc.setFontSize(12);
doc.text("No potential violations were identified based on the provided answers.", 15, 60);
}
doc.save(`Labor_Law_Violation_Report_${new Date().toISOString().split('T')[0]}.pdf`);
} catch (error) {
console.error("PDF Generation Error:", error);
} finally {
pdfDownloadButton.textContent = 'Download Report';
pdfDownloadButton.disabled = false;
}
}
// --- EVENT LISTENERS ---
mainContentContainer.addEventListener('change', function(e) {
if (e.target.type === 'radio') {
const { category, id } = e.target.dataset;
state.answers[category][id] = e.target.value;
}
});
pdfDownloadButton.addEventListener('click', downloadPdf);
// --- INITIALIZE ---
initializeAnalyzer();
});
