`;
timelineContainer.appendChild(entryEl);
});
downloadPdfBtn.style.display = 'inline-block';
}
function clearTimeline() {
if (confirm('Are you sure you want to delete your entire timeline? This cannot be undone.')) {
timelineData = [];
localStorage.removeItem('hairGrowthTimeline');
renderTimeline();
}
}
function generatePdf() {
if (timelineData.length === 0) return;
const { jsPDF } = jspdf;
const doc = new jsPDF();
const pageW = doc.internal.pageSize.getWidth();
// Header
doc.setFillColor(13, 148, 136); // Teal
doc.rect(0, 0, pageW, 25, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor(255, 255, 255);
doc.text('Hair Growth Timeline Report', pageW / 2, 15, { align: 'center' });
// Table
const tableData = timelineData.map(entry => {
const date = new Date(entry.date);
const displayDate = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
// **FIXED**: Corrected typo from toLocaleDate to toLocaleDateString
const formattedDate = displayDate.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
return [
formattedDate,
entry.notes,
entry.photoLogged ? 'Yes' : 'No'
];
});
doc.autoTable({
startY: 30,
theme: 'grid',
headStyles: { fillColor: [13, 148, 136] },
head: [['Date', 'Notes & Observations', 'Photo Logged']],
body: tableData,
columnStyles: {
0: { cellWidth: 35 },
1: { cellWidth: 'auto' },
2: { cellWidth: 25 }
}
});
// Disclaimer
doc.autoTable({
startY: doc.lastAutoTable.finalY + 10,
theme: 'plain',
body: [[ "Disclaimer: This log is a personal tracking tool. Consistency is key for observing changes. This report is not a substitute for professional medical advice." ]]
});
// Footer
const pageH = doc.internal.pageSize.getHeight();
doc.setLineWidth(0.5);
doc.setDrawColor(13, 148, 136);
doc.line(15, pageH - 15, pageW - 15, pageH - 15);
doc.setFontSize(8);
doc.setTextColor(128, 128, 128);
doc.text('Personal Progress Log', pageW / 2, pageH - 10, { align: 'center' });
doc.save('Hair_Growth_Timeline.pdf');
}
// Initial Render
changeTab(0);
renderTimeline();
});