import dayjs from "dayjs"; import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"; import { memo, useCallback, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { YearCalendar } from "@/components/ActivityCalendar"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { addMonths, formatMonth, getMonthFromDate, getYearFromDate, setYearAndMonth } from "@/lib/calendar-utils"; import type { MonthNavigatorProps } from "@/types/statistics"; export const MonthNavigator = memo(({ visibleMonth, onMonthChange, activityStats }: MonthNavigatorProps) => { const { i18n } = useTranslation(); const [isOpen, setIsOpen] = useState(false); const { currentMonth, currentYear, currentMonthNum } = useMemo( () => ({ currentMonth: dayjs(visibleMonth).toDate(), currentYear: getYearFromDate(visibleMonth), currentMonthNum: getMonthFromDate(visibleMonth), }), [visibleMonth], ); const monthLabel = useMemo( () => currentMonth.toLocaleString(i18n.language, { year: "numeric", month: "long" }), [currentMonth, i18n.language], ); const handlePrevMonth = useCallback(() => onMonthChange(addMonths(visibleMonth, -1)), [visibleMonth, onMonthChange]); const handleNextMonth = useCallback(() => onMonthChange(addMonths(visibleMonth, 1)), [visibleMonth, onMonthChange]); const handleDateClick = useCallback( (date: string) => { onMonthChange(formatMonth(date)); setIsOpen(false); }, [onMonthChange], ); const handleYearChange = useCallback( (year: number) => onMonthChange(setYearAndMonth(year, currentMonthNum)), [currentMonthNum, onMonthChange], ); return (
Select Month
); }); MonthNavigator.displayName = "MonthNavigator";