`;
finalPreviewContainer.innerHTML = html;
};
const downloadPDF = async () => {
const contentToPrint = document.getElementById('pdf-content');
if (!contentToPrint) {
displayError("No content to download.");
return;
}
if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') {
displayError("PDF generation library is not available.");
return;
}
try {
const { jsPDF } = window.jspdf;
const pdfCanvas = await html2canvas(contentToPrint, {
backgroundColor: '#ffffff', scale: 2
});
const imgData = pdfCanvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgProps = pdf.getImageProperties(imgData);
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`${courseData.title || 'course-outline'}.pdf`);
} catch(err) {
console.error("PDF generation failed:", err);
displayError("An error occurred while creating the PDF.");
}
};
const displayError = (message) => {
errorDiv.textContent = message;
errorDiv.classList.remove('hidden');
};
const hideError = () => errorDiv.classList.add('hidden');
// --- Event Listeners ---
tabButtons.forEach(button => {
button.addEventListener('click', () => {
// This direct navigation is disabled in favor of Next/Prev
// but could be enabled if desired.
// currentTab = parseInt(button.dataset.tab);
// updateTabs();
});
});
nextBtn.addEventListener('click', () => navigate(1));
prevBtn.addEventListener('click', () => navigate(-1));
addModuleBtn.addEventListener('click', addModule);
addLessonBtn.addEventListener('click', addLesson);
pdfBtn.addEventListener('click', downloadPDF);
// Initial setup
updateTabs();
updateModuleSelect();
});
