import { Button, ctw, Popover, PopoverContent, PopoverTrigger } from '@ballerine/ui'; import dayjs from 'dayjs'; import { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react'; import { useState } from 'react'; const today = dayjs(); const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; type MonthPickerProps = { date: Date; setDate: (date: Date) => void; minDate?: Date; }; export const MonthPicker = ({ date, setDate, minDate }: MonthPickerProps) => { const [open, setOpen] = useState(false); const [currentYear, setCurrentYear] = useState(today.year()); const dayjsDate = dayjs(date); const dayjsMinDate = minDate ? dayjs(minDate) : undefined; const handleMonthSelect = (monthIndex: number) => { const newDate = dayjs(date).year(currentYear).month(monthIndex); if (newDate.isSame(today, 'month') || newDate.isBefore(today, 'month')) { setDate(newDate.toDate()); setOpen(false); } }; const handleYearChange = (increment: number) => { setCurrentYear(prevYear => prevYear + increment); }; const isSameMonth = (date1: dayjs.Dayjs, date2: dayjs.Dayjs) => { return date1.isSame(date2, 'month'); }; const isMonthDisabled = (monthIndex: number) => { const monthDate = dayjs().year(currentYear).month(monthIndex).startOf('month'); return monthDate.isAfter(today, 'month'); }; return (
{currentYear}
{months.map((month, index) => ( ))}
); };