import React from 'react'; import { useStats } from '../../hooks/useStats'; import { timeToMinutes } from '../../utils/time'; interface TimetableProps { from_date: string; to_date: string; day_start: string; day_end: string; }; const Timetable: React.FC = ({ from_date, to_date, day_start, day_end }) => { const { timetable, isLoading } = useStats(from_date, to_date, day_start, day_end); if (isLoading) return
Loading timetable...
; if (!timetable?.slots || timetable.slots.length === 0) { return
No data available for this period.
; } // Grouping slots by date to make it easier to render rows const groupedSlots = timetable.slots.reduce((acc: any, slot) => { if (!acc[slot.date]) acc[slot.date] = []; acc[slot.date].push(slot); return acc; }, {}); return (

Sleep Timetable

{Object.keys(groupedSlots).map((date) => (

{date}

{groupedSlots[date].map((slot: any) => { const duration = Math.max(1, timeToMinutes(slot.slot_end) - timeToMinutes(slot.slot_start)); return (
{/* Only show text if there's enough space */}
{duration > 40 && {slot.slot_start}}
); })}
))}
); }; export default Timetable;