`).join('') + `
`;
loader.style.display = 'none';
pathContent.style.display = 'block';
};
const showError = (message) => {
setupError.textContent = message;
setupError.style.display = 'block';
};
const hideError = () => {
setupError.style.display = 'none';
};
// --- PDF Generation ---
async function generatePdf() {
const { goal, learningPath, overallAdvice } = lastResult;
if (!goal) return;
pdfContentArea.innerHTML = `
`).join('')}
Overall Advice
${data.overallAdvice}
Learning Path: ${goal}
${learningPath.map(step => `${step.step}. ${step.title}
${step.description}
Resources: ${step.resources}
Overall Advice
${overallAdvice}
`; pdfContentArea.style.display = 'block'; pdfContentArea.style.position = 'absolute'; pdfContentArea.style.left = '-9999px'; pdfContentArea.style.width = '800px'; try { const canvas = await html2canvas(pdfContentArea, { scale: 2, useCORS: true }); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgHeight = canvas.height * pdfWidth / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight); pdf.save(`Learning-Path-${goal.replace(/[^a-z0-9]/gi, '-')}.pdf`); } catch (error) { console.error("PDF generation failed:", error); alert("Could not generate PDF."); } finally { pdfContentArea.style.display = 'none'; } } // --- Event Listeners --- generatePathBtn.addEventListener('click', getLearningPath); downloadReportBtn.addEventListener('click', generatePdf); startOverBtn.addEventListener('click', () => switchView('setup')); // --- Initial State --- switchView('setup'); });