import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card" import { EmptyState } from "@/shared/components/ui/empty-state" import { CalendarX } from "lucide-react" import { ScheduleList } from "@/shared/components/schedule/schedule-list" import { cn } from "@/shared/lib/utils" import { useTranslations } from "next-intl" import type { StudentScheduleItem } from "@/modules/classes/types" const WEEKDAY_KEYS: Array<{ key: 1 | 2 | 3 | 4 | 5 | 6 | 7; label: string }> = [ { key: 1, label: "mon" }, { key: 2, label: "tue" }, { key: 3, label: "wed" }, { key: 4, label: "thu" }, { key: 5, label: "fri" }, { key: 6, label: "sat" }, { key: 7, label: "sun" }, ] const getTodayWeekday = (): 1 | 2 | 3 | 4 | 5 | 6 | 7 => { // getDay() returns 0 (Sun) - 6 (Sat); convert to 1 (Mon) - 7 (Sun) const WEEKDAY_MAP = [7, 1, 2, 3, 4, 5, 6] as const const day = new Date().getDay() if (day < 0 || day > 6) { throw new Error(`Invalid day from getDay(): ${day}`) } return WEEKDAY_MAP[day] } export function StudentScheduleView({ items }: { items: StudentScheduleItem[] }) { const t = useTranslations("student") if (items.length === 0) { return ( ) } const todayKey = getTodayWeekday() const itemsByDay = new Map() for (const item of items) { const list = itemsByDay.get(item.weekday) ?? [] list.push(item) itemsByDay.set(item.weekday, list) } for (const list of itemsByDay.values()) { list.sort((a, b) => a.startTime.localeCompare(b.startTime)) } return (
{WEEKDAY_KEYS.map((d) => { const dayItems = itemsByDay.get(d.key) ?? [] const isToday = d.key === todayKey return ( {t(`weekdays.${d.label}`)} {isToday && ( {t("scheduleView.today")} )} {dayItems.length === 0 ? (
{t("scheduleView.noClasses")}
) : ( ({ ...item, href: `/student/learning/courses/${encodeURIComponent(item.classId)}`, }))} variant="card" spacingClassName="space-y-3" /> )}
) })}
) }