Avg. Productivity
${productivity.toFixed(1)} / 10
`;
};
const downloadPDF = () => {
if (wellnessData.length === 0) { alert('No data to generate a report.'); return; }
const dashboardContent = document.getElementById('dashboard-content');
window.html2canvas(dashboardContent, { scale: 2, backgroundColor: '#ffffff' }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfMargin = 40;
const contentWidth = pdfWidth - (pdfMargin * 2);
const imgHeight = canvas.height * contentWidth / canvas.width;
pdf.setFontSize(22).setFont('helvetica', 'bold');
pdf.text('Personal Wellness Dashboard', pdfWidth / 2, pdfMargin, { align: 'center' });
pdf.setFontSize(12).setFont('helvetica', 'normal');
pdf.text(`Report Generated: ${new Date().toLocaleDateString('en-US')}`, pdfWidth / 2, pdfMargin + 20, { align: 'center' });
pdf.addImage(imgData, 'PNG', pdfMargin, pdfMargin + 40, contentWidth, imgHeight);
pdf.save('Wellness_Dashboard_Report.pdf');
});
};
const initialize = () => {
loadData();
renderDashboard();
logForm.addEventListener('submit', addLogEntry);
downloadPdfBtn.addEventListener('click', downloadPDF);
logDateInput.valueAsDate = new Date();
};
initialize();
});
function switchTab(tabId) {
document.getElementById('entry-tab').style.display = (tabId === 'entry') ? 'block' : 'none';
document.getElementById('dashboard-tab').style.display = (tabId === 'dashboard') ? 'block' : 'none';
document.getElementById('tab-entry-btn').classList.toggle('active', tabId === 'entry');
document.getElementById('tab-dashboard-btn').classList.toggle('active', tabId === 'dashboard');
}