`;
document.getElementById('clause-output-container').innerHTML = clause;
document.getElementById('pdf-download-section').classList.remove('hidden');
lucide.createIcons();
showTab(tabs.length - 1);
}
async function downloadPdf() {
const pdfLoader = document.getElementById('pdf-loader');
const downloadBtn = document.getElementById('downloadPdfBtn');
const content = document.getElementById('clause-output');
pdfLoader.classList.remove('hidden');
downloadBtn.disabled = true;
try {
const canvas = await html2canvas(content, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF('p', 'pt', 'letter');
const pdfWidth = pdf.internal.pageSize.getWidth();
const margin = 60;
const contentWidth = pdfWidth - (margin * 2);
pdf.setFont('Times-Roman');
pdf.setFontSize(18);
pdf.text("Arbitration Clause", pdfWidth / 2, margin, { align: 'center' });
const text = Array.from(content.getElementsByTagName('p')).map(p => p.innerText);
pdf.setFontSize(12);
const splitText = pdf.splitTextToSize(text.join('\n\n'), contentWidth);
pdf.text(splitText, margin, margin + 30);
pdf.save('Arbitration-Clause.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("There was an error generating the PDF. Please try again.");
} finally {
pdfLoader.classList.add('hidden');
downloadBtn.disabled = false;
}
}
// Event Listeners
generateBtn.addEventListener('click', generateClause);
downloadPdfBtn.addEventListener('click', downloadPdf);
// Initial UI setup
showTab(currentTab);
lucide.createIcons();
});
