`).join('');
} else {
remediationEl.innerHTML = `
Congratulations! No non-compliant items found.
`;
}
updateChart(sectionScores);
};
const updateChart = (sectionScores) => {
const ctx = document.getElementById('section-score-chart')?.getContext('2d');
if (!ctx) return;
const data = {
labels: Object.keys(sectionScores),
datasets: [{
label: 'Compliance Score (%)',
data: Object.values(sectionScores),
backgroundColor: 'rgba(59, 130, 246, 0.5)',
borderColor: 'rgba(59, 130, 246, 1)',
borderWidth: 1
}]
};
if (sectionScoreChart) {
sectionScoreChart.data = data;
sectionScoreChart.update();
} else {
sectionScoreChart = new Chart(ctx, {
type: 'bar',
data: data,
options: { scales: { y: { beginAtZero: true, max: 100 } }, plugins: { legend: { display: false } } }
});
}
};
const generatePDF = () => {
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-content');
const pdfBtnContainer = document.getElementById('pdf-button-container');
if (!pdfContent || !pdfBtnContainer) return;
pdfBtnContainer.style.display = 'none';
html2canvas(pdfContent, { scale: 2, useCORS: true }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgWidth = pdfWidth - 20;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.setFontSize(22);
pdf.setFont('helvetica', 'bold');
pdf.text('PCI DSS Compliance Report', pdfWidth / 2, 15, { align: 'center' });
pdf.addImage(imgData, 'PNG', 10, 25, imgWidth, imgHeight);
pdf.save('pci-dss-compliance-report.pdf');
pdfBtnContainer.style.display = 'block';
}).catch(err => {
console.error("Error generating PDF:", err);
pdfBtnContainer.style.display = 'block';
});
};
// --- Initial Setup ---
initTool();
});
