import { useMediaQuery, useTheme } from '@mui/material'; import React from 'react'; import { dateToYYYYMMDD, isSameDay } from "@/core/lib/date"; import { DayProps } from "./CalendarComponent"; interface CalendarDayProps { day: DayProps; currentMonth: number; currentDate: Date; selectedDay: DayProps; onClick: (day: DayProps) => void; } const CalendarDay: React.FC = ({ day, currentMonth, currentDate, selectedDay, onClick }) => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const isTablet = useMediaQuery(theme.breakpoints.down('md')); const isSelected = isSameDay(day.date, selectedDay.date); const isToday = isSameDay(day.date, currentDate); const isClickable = day.date.getTime() <= currentDate.getTime(); const isWeekend = day.date.getDay() === 6 || day.date.getDay() === 0; const getDayColor = (): string => { if (isSelected || isToday) return 'white'; if (!isClickable) return 'gray'; return isWeekend ? '#E53945' : 'black'; }; const getDaySize = () => { if (isMobile) return 35; if (isTablet) return 40; return 50; }; const getDotSize = () => { if (isMobile) return 8; if (isTablet) return 9; return 10; }; const hasDayEntry = () => { return day.measurements.length > 0 || day.weightEntry !== undefined || day.workoutSession !== undefined; }; const handleClick = () => { if (isClickable) { onClick(day); } }; const daySize = getDaySize(); const dotSize = getDotSize(); return (
{day.date.getDate()}
{hasDayEntry() && (
)}
); }; export default CalendarDay;