document.addEventListener('DOMContentLoaded', () => { // Set default times if inputs exist const startInput = document.getElementById('start_time'); const endInput = document.getElementById('end_time'); if (startInput && endInput) { const now = new Date(); const yesterday = new Date(now); yesterday.setHours(now.getHours() - 8); // Format to YYYY-MM-DDTHH:mm const formatDate = (date) => { const pad = (num) => String(num).padStart(2, '0'); return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`; }; if (!startInput.value) startInput.value = formatDate(yesterday); if (!endInput.value) endInput.value = formatDate(now); } // Form validation const form = document.querySelector('form'); if (form) { form.addEventListener('submit', (e) => { const start = new Date(startInput.value); const end = new Date(endInput.value); if (end <= start) { e.preventDefault(); alert('Wake up time must be after bed time!'); } }); } // Rating selection visual feedback (optional since CSS handles it, but good for accessibility) const ratingLabels = document.querySelectorAll('.rating-label'); ratingLabels.forEach(label => { label.addEventListener('click', () => { ratingLabels.forEach(l => l.style.borderColor = ''); label.style.borderColor = 'var(--accent-teal)'; }); }); });