import { CalendarDays, CalendarX } from "lucide-react" import { ScheduleList } from "@/shared/components/schedule/schedule-list" import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card" import { EmptyState } from "@/shared/components/ui/empty-state" import { cn } from "@/shared/lib/utils" import type { ChildScheduleItem, ChildWeeklyScheduleItem } from "@/modules/parent/types" const WEEKDAY_LABELS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] as const const toWeekdayIndex = (w: 1 | 2 | 3 | 4 | 5 | 6 | 7): 0 | 1 | 2 | 3 | 4 | 5 | 6 => (w - 1) as 0 | 1 | 2 | 3 | 4 | 5 | 6 const isToday = (w: 1 | 2 | 3 | 4 | 5 | 6 | 7): boolean => { const today = new Date().getDay() const normalizedToday = today === 0 ? 7 : today return w === normalizedToday } export function ChildScheduleCard({ items, childName, weeklyItems, }: { items: ChildScheduleItem[] childName: string /** 完整周课表(可选)。提供时切换为周课表视图。 */ weeklyItems?: ChildWeeklyScheduleItem[] }) { const hasSchedule = items.length > 0 const hasWeekly = weeklyItems && weeklyItems.length > 0 if (hasWeekly) { const grouped: Record = {} for (const item of weeklyItems!) { const key = item.weekday if (!grouped[key]) grouped[key] = [] grouped[key].push(item) } const weekdays = Object.keys(grouped).map(Number).sort((a, b) => a - b) as Array<1 | 2 | 3 | 4 | 5 | 6 | 7> return ( {childName}'s Weekly Schedule {weekdays.map((w) => { const dayItems = grouped[w] const today = isToday(w) const label = WEEKDAY_LABELS[toWeekdayIndex(w)] return (
{label} {today ? ( Today ) : null}
({ id: d.id, classId: d.classId, className: d.className, course: d.course, startTime: d.startTime, endTime: d.endTime, location: d.location ?? null, }))} variant="separator" spacingClassName="space-y-2" />
) })}
) } return ( {childName}'s Today Schedule {!hasSchedule ? ( ) : ( )} ) }