`).join('');
pdfContentEl.classList.remove('hidden');
html2canvas(pdfContentEl, { scale: 2 }).then(canvas => {
pdfContentEl.classList.add('hidden');
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const margin = 40;
const imgWidth = pdfWidth - (margin * 2);
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', margin, margin, imgWidth, imgHeight);
pdf.save('email-follow-up-sequence.pdf');
}).catch(err => {
console.error("Error generating PDF:", err);
pdfContentEl.classList.add('hidden');
});
};
// --- Event Listeners ---
generateBtn.addEventListener('click', handleGeneration);
pdfBtn.addEventListener('click', handleDownloadPdf);
modalCloseBtn.addEventListener('click', closeModal);
sequenceTimeline.addEventListener('click', (e) => {
if (e.target.classList.contains('preview-btn')) {
openModal(e.target.dataset.index);
}
});
});