`;
});
pdfContent.innerHTML = reportHTML;
};
// --- UI & NAVIGATION ---
const showTab = (tabIndex) => {
tabs.forEach((tab, index) => tab.classList.toggle('hidden', index !== tabIndex));
tabNavs.forEach((nav, index) => nav.classList.toggle('active', index === tabIndex));
prevBtn.style.visibility = tabIndex === 0 ? 'hidden' : 'visible';
nextBtn.textContent = tabIndex === tabs.length - 1 ? 'Start Over' : 'Next';
nextBtn.classList.toggle('bg-gray-500', tabIndex === tabs.length - 1);
nextBtn.classList.toggle('hover:bg-gray-600', tabIndex === tabs.length - 1);
nextBtn.classList.toggle('bg-blue-600', tabIndex < tabs.length - 1);
nextBtn.classList.toggle('hover:bg-blue-700', tabIndex < tabs.length - 1);
};
const nextPrev = (direction) => {
let newTab = currentTab + direction;
if (newTab === tabs.length-1) {
collectAnswers();
renderReport();
}
if (nextBtn.textContent === 'Start Over' && direction === 1) {
userAnswers = {};
renderForms();
newTab = 0;
}
if (newTab >= 0 && newTab < tabs.length) {
currentTab = newTab;
showTab(currentTab);
}
};
// --- EVENT HANDLERS ---
const collectAnswers = () => {
const formData = new FormData(gdprForm);
new FormData(hipaaForm).forEach((value, key) => formData.append(key, value));
for (let [key, value] of formData.entries()) {
userAnswers[key] = value;
}
};
const downloadPDF = () => {
const { jsPDF } = window.jspdf;
if (!pdfContent) return;
html2canvas(pdfContent, { scale: 2, backgroundColor: '#ffffff', 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 canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / canvasHeight;
const imgWidth = pdfWidth - 20;
const imgHeight = imgWidth / ratio;
pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight);
pdf.save('Data-Protection-Audit-Report.pdf');
});
};
prevBtn.addEventListener('click', () => nextPrev(-1));
nextBtn.addEventListener('click', () => nextPrev(1));
downloadPdfBtn.addEventListener('click', downloadPDF);
// --- INITIALIZATION ---
renderForms();
showTab(currentTab);
});
