`;
outputContainer.innerHTML = html;
};
// --- PDF Download ---
const downloadPDF = async () => {
if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') {
console.error("jsPDF or html2canvas is not loaded.");
return;
}
const { jsPDF } = window.jspdf;
const content = document.getElementById('pdf-output-container');
downloadPdfBtn.textContent = 'Generating...';
downloadPdfBtn.disabled = true;
try {
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'letter' });
await pdf.html(content, {
margin: [72, 72, 72, 72], // Standard 1-inch margins
autoPaging: 'text',
width: 468, // Letter width (612pt) - margins (72pt * 2)
windowWidth: 700,
html2canvas: { scale: 0.8, useCORS: true }
});
const fileName = `parental_consent_form_${getText('minorName', 'minor')}.pdf`.toLowerCase().replace(/[^a-z0-9]/gi, '_');
pdf.save(fileName);
} catch (error) {
console.error("Error generating PDF:", error);
} finally {
downloadPdfBtn.textContent = 'Download as PDF';
downloadPdfBtn.disabled = false;
}
};
// --- Event Listeners ---
tabs.forEach(tab => tab.addEventListener('click', () => showTab(parseInt(tab.dataset.tab, 10))));
nextBtn.addEventListener('click', () => { if (currentTab < totalTabs) showTab(currentTab + 1); });
prevBtn.addEventListener('click', () => { if (currentTab > 1) showTab(currentTab - 1); });
if(downloadPdfBtn) downloadPdfBtn.addEventListener('click', downloadPDF);
// --- Initial Setup ---
showTab(1);
});
