`;
const { jsPDF } = window.jspdf;
html2canvas(pdfContentEl, { scale: 2 }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgProps = pdf.getImageProperties(imgData);
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`Proctoring_Report_${student.name.replace(/\s/g, '_')}.pdf`);
});
}
// --- TAB NAVIGATION ---
window.changeTab = function(evt, tabName) {
document.querySelectorAll(".tab-content").forEach(tc => tc.classList.remove('active'));
document.querySelectorAll(".tab-button").forEach(tb => tb.classList.remove('active'));
document.getElementById(tabName).classList.add('active');
const button = evt ? evt.currentTarget : document.querySelector(`.tab-button[onclick*="'${tabName}'"]`);
if(button) button.classList.add('active');
currentTab = tabName;
updateNavButtons();
}
function updateNavButtons() {
const currentIndex = tabs.indexOf(currentTab);
prevBtn.disabled = currentIndex === 0;
nextBtn.disabled = currentIndex === tabs.length - 1;
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
}
window.navigateTabs = function(direction) {
const currentIndex = tabs.indexOf(currentTab);
let newIndex;
if (direction === 'next' && currentIndex < tabs.length - 1) newIndex = currentIndex + 1;
else if (direction === 'prev' && currentIndex > 0) newIndex = currentIndex - 1;
if (newIndex !== undefined) changeTab(null, tabs[newIndex]);
}
// --- INITIALIZATION ---
addWhitelistBtn.addEventListener('click', addWhitelistItem);
downloadPdfBtn.addEventListener('click', downloadPDF);
renderStudentGrid();
renderWhitelist();
updateNavButtons();
});
