Warnings
${warningChecks}
Vulnerabilities
${failedChecks}
Issues & Recommendations
${issuesHtml}
`;
// Render Chart
const chartCtx = document.getElementById('scanResultsChart').getContext('2d');
if (charts.results) charts.results.destroy();
charts.results = new Chart(chartCtx, {
type: 'doughnut',
data: {
labels: ['Passed', 'Warnings', 'Failed'],
datasets: [{ data: [passedChecks, warningChecks, failedChecks], backgroundColor: ['#22c55e', '#facc15', '#ef4444'] }]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } }
});
lucide.createIcons();
document.getElementById('download-pdf-btn').addEventListener('click', generatePdf);
};
const renderDataConfig = () => {
const configContent = document.getElementById('content-data-config');
if (!configContent) return;
const checksHtml = appData.securityChecks.map(check => `
${check.category}
`).join('');
configContent.innerHTML = `
Scanner Configuration
Set the simulated status for each security check to model different scenarios.
${checksHtml}
`;
document.getElementById('update-data-btn').addEventListener('click', handleConfigUpdate);
};
const handleConfigUpdate = () => {
document.querySelectorAll('.check-status-select').forEach(select => {
const checkId = select.dataset.id;
const check = appData.securityChecks.find(c => c.id === checkId);
if(check) {
check.status = select.value;
}
});
scanResult = null; // Force recalculation
renderDashboard();
alert('Scan configuration updated and re-run!');
switchTab(0);
};
const generatePdf = () => {
loadingOverlay.style.display = 'flex';
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-content-area');
const pdfHeader = document.getElementById('pdf-header');
document.getElementById('pdf-generated-date').textContent = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
pdfHeader.classList.remove('hidden');
html2canvas(pdfContent, { scale: 2, useCORS: true, logging: false })
.then(canvas => {
pdfHeader.classList.add('hidden');
const imgData = canvas.toDataURL('image/jpeg', 0.95);
const pdf = new jsPDF({ orientation: 'landscape', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, imgHeight);
pdf.save('Payment-Security-Report.pdf');
loadingOverlay.style.display = 'none';
}).catch(err => {
console.error("PDF generation failed:", err);
pdfHeader.classList.add('hidden');
loadingOverlay.style.display = 'none';
alert('An error occurred generating the PDF.');
});
};
// --- TAB NAVIGATION & INITIALIZATION ---
const switchTab = (tabIndex) => {
activeTabIndex = tabIndex;
document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex));
document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex));
updateNavButtons();
};
const updateNavButtons = () => {
prevTabBtn.disabled = activeTabIndex === 0;
nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1;
};
const initializeUI = () => {
const tabs = [
{ name: 'Security Dashboard', id: 'dashboard' },
{ name: 'Scanner Configuration', id: 'data-config' }
];
tabIdentifiers = tabs.map(t => t.id);
tabsContainer.innerHTML = tabs.map(tab => `
`).join('');
mainContent.innerHTML = tabs.map(tab => `
`).join('');
tabs.forEach((tab, index) => {
document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index));
});
renderDashboard();
renderDataConfig();
switchTab(0);
};
initializeUI();
lucide.createIcons();
prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); });
nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); });
});