import React from 'react'; import { generateWeekDays, getWeekNumber, getLunarInfo, isSameDay } from '../utils/calendarUtils'; import * as TimeService from '../../../os/TimeService'; import { useAppStrings } from '../../../os/useAppStrings'; import { strings } from '../res/strings'; import { stringsEn } from '../res/strings.en'; interface CalendarWeekViewProps { currentDate: Date; onDayClick?: (date: Date) => void; weekStartDay?: 'monday' | 'sunday'; } export const CalendarWeekView: React.FC = ({ currentDate, onDayClick, weekStartDay = 'monday' }) => { const s = useAppStrings(strings, stringsEn); const weekLabelsMon = [s.weekday_mon, s.weekday_tue, s.weekday_wed, s.weekday_thu, s.weekday_fri, s.weekday_sat, s.weekday_sun]; const weekLabelsSun = [s.weekday_sun, s.weekday_mon, s.weekday_tue, s.weekday_wed, s.weekday_thu, s.weekday_fri, s.weekday_sat]; const weekLabels = weekStartDay === 'sunday' ? weekLabelsSun : weekLabelsMon; const weekDays = generateWeekDays(currentDate, weekStartDay, weekLabels); const weekNum = getWeekNumber(currentDate); const hours = Array.from({ length: 24 }, (_, i) => i); const now = TimeService.getDate(); const curH = now.getHours(); const curM = now.getMinutes(); return (
{/* ===== Week strip ===== */}
{/* Week number column */}
{weekNum}
{/* 7 day columns */}
{weekDays.map((day, idx) => { const selected = isSameDay(day.date, currentDate); const lunar = getLunarInfo(day.date); return (
onDayClick?.(day.date)} > {/* Weekday label */} {day.weekDay} {/* Date number */}
{day.date.getDate()}
{/* Lunar */} {lunar.label}
); })}
{/* ===== Hourly time grid ===== */}
{/* Hour rows */} {hours.map((h) => (
{String(h).padStart(2, '0')}:00
))} {/* Current time red line */}
{String(curH).padStart(2, '0')}:{String(curM).padStart(2, '0')}
); };