`;
document.body.appendChild(pdfContainer);
window.html2canvas(pdfContainer, { scale: 2 }).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 contentWidth = pdfWidth - 80;
const imgHeight = canvas.height * contentWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 40, 40, contentWidth, imgHeight);
pdf.save('Daily_Log_Report.pdf');
document.body.removeChild(pdfContainer);
});
};
const setDateTimeToNow = () => {
const now = new Date();
logDateInput.valueAsDate = now;
logTimeInput.value = now.toTimeString().substring(0, 5);
};
// --- Initialization ---
const initialize = () => {
loadData();
renderLogHistory();
dailyLogForm.addEventListener('submit', addLogEntry);
downloadPdfBtn.addEventListener('click', downloadPDF);
setDateTimeToNow();
};
initialize();
});
function toggleLogDetails() {
const logType = document.querySelector('input[name="log-type"]:checked').value;
document.getElementById('diaper-details').style.display = (logType === 'diaper') ? 'block' : 'none';
document.getElementById('feeding-details').style.display = (logType === 'feeding') ? 'block' : 'none';
}
