import DayColumn from './DayColumn' function addDays(date, n) { const d = new Date(date) d.setDate(d.getDate() + n) return d } function formatDateRange(monday) { const sunday = addDays(monday, 6) const opts = { month: 'short', day: 'numeric' } const startStr = monday.toLocaleDateString('en-US', opts) const endStr = sunday.toLocaleDateString('en-US', { month: sunday.getMonth() !== monday.getMonth() ? 'short' : undefined, day: 'numeric', }) return `${startStr} – ${endStr}` } function toDateKey(date) { return date.toISOString().slice(0, 10) } function getMondayOfWeek(date) { const d = new Date(date) const day = d.getDay() d.setDate(d.getDate() + (day === 0 ? -6 : 1 - day)) d.setHours(0, 0, 0, 0) return d } // Returns the two shifts that form the next/active test window. // Window = Shift 3 of day D → Shift 1 of day D+1 function getNextTestWindow() { const now = new Date() const hour = now.getHours() const tod = new Date(now); tod.setHours(0, 0, 0, 0) // midnight–1AM: still inside shift 3 that started yesterday if (hour < 1) { return { shift3Date: toDateKey(addDays(tod, -1)), shift1Date: toDateKey(tod) } } // 1AM–5PM: shift 1 finished or in daytime gap — next window starts at 5PM today // 5PM–midnight: currently inside shift 3 of today // Both cases: upcoming/active window is shift 3 today + shift 1 tomorrow return { shift3Date: toDateKey(tod), shift1Date: toDateKey(addDays(tod, 1)) } } // scheduleData: { "YYYY-MM-DD": { shift1: [...], shift2: [...], shift3: [...] }, ... } export default function Calendar({ scheduleData = {}, daytimeDateKey = null, weekStart, onWeekChange }) { const today = new Date() today.setHours(0, 0, 0, 0) const activeWindow = getNextTestWindow() const days = Array.from({ length: 7 }, (_, i) => addDays(weekStart, i)) // Reorder columns: Sun Mon Tue Wed Thu Fri Sat // weekStart is Monday, so days[0]=Mon ... days[6]=Sun → put Sunday first const orderedDays = [ ...days.slice(0, 7)] return (