`;
document.getElementById('noticePreview').innerHTML = noticeHTML;
document.getElementById('pdf-render-area').innerHTML = noticeHTML;
}
/**
* Downloads the generated notice as a PDF file.
*/
async function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-render-area');
if (!pdfContent) return;
downloadPdfBtn.textContent = 'Generating...';
downloadPdfBtn.disabled = true;
pdfContent.classList.remove('hidden');
try {
const canvas = await html2canvas(pdfContent, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' });
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Eviction_Notice.pdf');
} catch (error) {
console.error('Error generating PDF:', error);
} finally {
pdfContent.classList.add('hidden');
downloadPdfBtn.textContent = 'Download Notice as PDF';
downloadPdfBtn.disabled = false;
}
}
// --- EVENT LISTENERS ---
evictionReasonSelect.addEventListener('change', handleReasonChange);
downloadPdfBtn.addEventListener('click', downloadPDF);
// --- INITIALIZATION ---
showTab(currentTab);
handleReasonChange(); // Set initial state of conditional fields
});
