`;
reportOutput.innerHTML += resultHTML;
});
lucide.createIcons();
};
const updateNavButtons = () => {
prevBtn.disabled = currentTab === 'consent';
nextBtn.disabled = currentTab === 'report';
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
// --- EVENT HANDLERS & LOGIC ---
const handleInputChange = (e) => {
if (e.target.type === 'radio') {
answers[e.target.name] = e.target.value;
}
};
window.switchTab = (tabId) => {
// If moving to the report tab, generate it first
if (tabId === 'report') {
generateAndRenderReport();
}
currentTab = tabId;
Object.values(tabContents).forEach(content => content.classList.add('hidden'));
Object.values(tabButtons).forEach(button => button.classList.replace('tab-active', 'tab-inactive'));
if(tabContents[tabId]) tabContents[tabId].classList.remove('hidden');
if(tabButtons[tabId]) tabButtons[tabId].classList.replace('tab-inactive', 'tab-active');
updateNavButtons();
};
const navigateTabs = (direction) => {
const currentIndex = tabs.indexOf(currentTab);
let nextIndex = currentIndex + direction;
if (nextIndex >= 0 && nextIndex < tabs.length) {
switchTab(tabs[nextIndex]);
}
};
downloadPdfBtn.addEventListener('click', () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(18);
doc.text("E-Signature Process Validation Report", 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Report generated on: ${new Date().toLocaleDateString()}`, 14, 30);
const tableColumn = ["Validation Point", "Status", "Recommendation"];
const tableRows = [];
questions.forEach(q => {
const answer = answers[q.id];
const passed = answer === q.passIf;
const itemData = [
q.text.split('?')[0],
passed ? 'Compliant' : 'Needs Review',
passed ? 'N/A' : q.recommendation
];
tableRows.push(itemData);
});
doc.autoTable({
head: [tableColumn],
body: tableRows,
startY: 40,
theme: 'grid',
headStyles: { fillColor: [45, 102, 193] },
didParseCell: function (data) {
if (data.section === 'body' && data.column.index === 1) {
if (data.cell.raw === 'Compliant') {
data.cell.styles.textColor = [0, 128, 0];
} else if (data.cell.raw === 'Needs Review') {
data.cell.styles.textColor = [217, 119, 6];
}
}
}
});
doc.save('e-signature-validation-report.pdf');
});
// --- INITIALIZATION ---
renderQuestions();
updateNavButtons();
lucide.createIcons();
// Attach event listeners to the tab content containers
Object.values(tabContents).forEach(container => {
container.addEventListener('change', handleInputChange);
});
prevBtn.addEventListener('click', () => navigateTabs(-1));
nextBtn.addEventListener('click', () => navigateTabs(1));
});