Circadian Rhythm Optimizer Circadian Rhythm Optimizer Align your day with your body's natural clock. What time do you want to wake up? Generate Schedule Your Optimized Daily Schedule Download Schedule as PDF Disclaimer: This schedule is a suggestion based on general circadian science. It is not medical advice. Listen to your body and adjust as needed. ${item.description} `).join(''); scheduleSubtitle.textContent = `Based on a ${formatTime(wakeUpTime)} wake-up time. Sunrise is at ${formatTime(sunrise)}.`; resultsSection.classList.remove('hidden'); }; // --- 5. PDF GENERATION --- const handlePdfDownload = () => { const { jsPDF } = window.jspdf; const contentToPrint = document.getElementById('printable-content'); const buttonContainer = document.getElementById('pdf-button-container'); if (!contentToPrint) return; buttonContainer.classList.add('hide-for-pdf'); html2canvas(contentToPrint, { scale: 2, useCORS: true }).then(canvas => { buttonContainer.classList.remove('hide-for-pdf'); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / pdfWidth; const calculatedHeight = canvasHeight / ratio; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, calculatedHeight); pdf.save('Circadian_Rhythm_Schedule.pdf'); }).catch(err => { buttonContainer.classList.remove('hide-for-pdf'); showError('An error occurred while generating the PDF.'); }); }; // --- 6. EVENT LISTENERS --- calculateBtn.addEventListener('click', generateSchedule); downloadPdfBtn.addEventListener('click', handlePdfDownload); });