`;
});
html += `
`;
resultsContainer.innerHTML = html;
// Enable and switch to the results tab
tabButtons.tab2.classList.remove('disabled');
switchTab('tab2');
}
function downloadPdf() {
if (!scheduleData) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Header
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text('Your Personalized Circadian Schedule', 105, 20, { align: 'center' });
// User Inputs Summary
doc.setFontSize(12);
doc.setFont('helvetica', 'normal');
doc.text(`Report for: ${document.getElementById('timezone').value.replace(/_/g, ' ')}`, 20, 35);
doc.text(`Primary Goal: ${document.getElementById('primary-goal').options[document.getElementById('primary-goal').selectedIndex].text}`, 20, 42);
// Schedule Table
const tableData = scheduleData.map(item => [item.time, item.activity, item.description]);
doc.autoTable({
startY: 50,
head: [['Time', 'Activity', 'Recommendation']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: [79, 70, 229] }, // Indigo
didParseCell: function(data) {
// Custom styling for emphasis
if (data.row.index >= 0 && scheduleData[data.row.index].emphasis) {
if (data.column.index === 2) { // Description column
data.cell.styles.fontStyle = 'bold';
data.cell.styles.textColor = [29, 78, 216]; // blue-700
}
}
}
});
doc.save('Circadian-Rhythm-Schedule.pdf');
}
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', generateSchedule);
prevBtn.addEventListener('click', () => switchTab('tab1'));
downloadBtn.addEventListener('click', downloadPdf);
// --- INITIALIZATION ---
populateTimezoneSelect();
});
