`;
checklistEl.appendChild(li);
});
resultsPanel.classList.remove('hidden');
}
function downloadPdf() {
if (!analysisResults) return;
const { jsPDF } = window.jspdf;
const pdf = new jsPDF();
pdf.setFont('helvetica', 'bold');
pdf.setFontSize(22);
pdf.text('Compliance Report', 105, 20, { align: 'center' });
pdf.setFontSize(12);
pdf.text(`Regulation: ${analysisResults.regulationName}`, 15, 40);
pdf.text(`Date: ${new Date().toLocaleDateString()}`, 15, 50);
const overallStatus = analysisResults.issuesFound > 0 ? `Issues Found (${analysisResults.issuesFound})` : 'No Issues Detected';
pdf.text(`Overall Status: ${overallStatus}`, 15, 60);
const head = [['Check', 'Status', 'Details']];
const body = analysisResults.results.map(r => [r.name, r.status.toUpperCase(), r.details]);
pdf.autoTable({
startY: 70,
head: head,
body: body,
theme: 'grid',
headStyles: { fillColor: '#1e293b' },
didParseCell: function(data) {
if (data.section === 'body') {
if (data.cell.raw === 'PASS') data.cell.styles.textColor = '#16a34a';
if (data.cell.raw === 'FAIL') data.cell.styles.textColor = '#dc2626';
if (data.cell.raw === 'WARN') data.cell.styles.textColor = '#f59e0b';
}
}
});
pdf.save('Compliance_Report.pdf');
}
checkBtn.addEventListener('click', runChecks);
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
});
