`).join('');
container.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.addEventListener('change', updateProgress);
});
updateProgress();
}
function updateProgress() {
const regulation = document.getElementById('regulation-select').value;
const totalQuestions = auditData[regulation].questions.length;
const answeredQuestions = document.querySelectorAll('#checklist-container input[type="radio"]:checked').length;
const percentage = totalQuestions > 0 ? Math.round((answeredQuestions / totalQuestions) * 100) : 0;
document.getElementById('progress-bar').style.width = `${percentage}%`;
document.getElementById('progress-text').textContent = `${percentage}%`;
}
// --- Report Generation ---
function generateReport() {
const regulation = document.getElementById('regulation-select').value;
const data = auditData[regulation];
const subject = document.getElementById('audit-subject').value;
const results = [];
data.questions.forEach((item, index) => {
const checked = document.querySelector(`input[name="q${index}"]:checked`);
results.push({
question: item.q,
answer: checked ? checked.value : 'unanswered',
recommendation: item.r
});
});
const yesCount = results.filter(r => r.answer === 'yes').length;
const applicableCount = results.filter(r => r.answer === 'yes' || r.answer === 'no').length;
const score = applicableCount > 0 ? Math.round((yesCount / applicableCount) * 100) : 100;
let riskLevel, riskColor;
if (score >= 90) { riskLevel = "Low"; riskColor = "text-green-600"; }
else if (score >= 60) { riskLevel = "Medium"; riskColor = "text-yellow-600"; }
else { riskLevel = "High"; riskColor = "text-red-600"; }
const nonCompliantItems = results.filter(r => r.answer === 'no').map(item =>
`
`
).join('');
const reportHTML = `
`;
document.getElementById('report-output').innerHTML = reportHTML;
}
// --- PDF Download ---
const downloadPdfBtn = document.getElementById('download-pdf-btn');
async function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdfPreview = document.getElementById('pdf-preview');
const container = document.getElementById('pdf-container');
const reportContent = document.getElementById('report-output').innerHTML;
pdfPreview.innerHTML = `
${item.question}
Recommendation: ${item.recommendation}
Compliance Score
${score}%
Risk Level
${riskLevel}
Audit Subject: ${subject}
Framework: ${data.name}
Date: ${new Date().toLocaleDateString('en-US')}
Areas for Review
-
${nonCompliantItems || "
- No immediate areas for review identified based on responses. "}
