`;
certificateOutput.innerHTML = certHTML;
};
// --- EVENT LISTENERS ---
tabs.forEach((tab, index) => {
if (tab.btn) tab.btn.addEventListener('click', () => {
// Prevent jumping to tabs if validation on tab 3 is not complete
if (index > 2 && !checkVerificationTab()) return;
currentTab = index;
updateTabUI();
});
});
nextBtn.addEventListener('click', () => {
if (currentTab < tabs.length - 1) { currentTab++; updateTabUI(); }
});
prevBtn.addEventListener('click', () => {
if (currentTab > 0) { currentTab--; updateTabUI(); }
});
// Add event listeners to checkboxes on verification tab to enable/disable next button
if (tabs[2].content) {
tabs[2].content.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
checkbox.addEventListener('change', updateTabUI);
});
}
downloadPdfBtn.addEventListener('click', () => {
const { jsPDF } = window.jspdf;
const pdfExportContainer = document.getElementById('pdfExportContainer');
// Use the already generated certificate HTML
pdfExportContainer.innerHTML = `
${certificateOutput.innerHTML}
`;
html2canvas(pdfExportContainer, { 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 pdfHeight = pdf.internal.pageSize.getHeight();
const canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / canvasHeight;
const imgWidth = pdfWidth - 20; // with margin
const imgHeight = imgWidth / ratio;
let finalImgHeight = imgHeight > (pdfHeight - 20) ? (pdfHeight - 20) : imgHeight;
pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, finalImgHeight);
pdf.save('witness_verification_certificate.pdf');
pdfExportContainer.innerHTML = ''; // Clean up
});
});
// --- INITIALIZE APP ---
document.getElementById('signingDate').valueAsDate = new Date();
updateTabUI();
});
