import { Button } from "antd"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { ProBottomSheet } from "../ProBottomSheet/ProBottomSheet"; import Picker from "../WheelPicker"; interface DatePickerBottomSheetProps { isOpen: boolean; onClose: () => void; onDateSelect?: (date: { month: string; day: string; year: string }) => void; initialDate?: Date; } export default function DatePickerBottomSheet({ isOpen, onClose, onDateSelect, initialDate = new Date(), }: DatePickerBottomSheetProps) { const { t } = useTranslation(); const [selectedDate, setSelectedDate] = useState({ month: (initialDate.getMonth() + 1).toString().padStart(2, "0"), day: initialDate.getDate().toString().padStart(2, "0"), year: initialDate.getFullYear().toString(), }); // Generate picker options const pickerOptions = useMemo(() => { const months = [ { value: "01", label: t("common.January") }, { value: "02", label: t("common.February") }, { value: "03", label: t("common.March") }, { value: "04", label: t("common.April") }, { value: "05", label: t("common.May") }, { value: "06", label: t("common.June") }, { value: "07", label: t("common.July") }, { value: "08", label: t("common.August") }, { value: "09", label: t("common.September") }, { value: "10", label: t("common.October") }, { value: "11", label: t("common.November") }, { value: "12", label: t("common.December") }, ]; const days = Array.from({ length: 31 }, (_, i) => ({ value: (i + 1).toString().padStart(2, "0"), label: (i + 1).toString(), })); const currentYear = new Date().getFullYear(); const years = Array.from( { length: currentYear - 10 - 1900 + 1 }, (_, i) => { const year = 1900 + i; return { value: year.toString(), label: year.toString(), }; }, ); return { month: months, day: days, year: years, }; }, [t]); const handleDateChange = (month: string, day: string, year: string) => { setSelectedDate((prev) => ({ ...prev, month, day, year, })); }; const handleConfirm = () => { onDateSelect?.(selectedDate); onClose(); }; const handleTouchStart = (e: React.TouchEvent) => { e.stopPropagation(); }; const handleTouchMove = (e: React.TouchEvent) => { e.stopPropagation(); }; const handleTouchEnd = (e: React.TouchEvent) => { e.stopPropagation(); }; const handleMouseDown = (e: React.MouseEvent) => { e.stopPropagation(); }; const handleMouseMove = (e: React.MouseEvent) => { e.stopPropagation(); }; const handleMouseUp = (e: React.MouseEvent) => { e.stopPropagation(); }; const handleWheel = (e: React.WheelEvent) => { e.stopPropagation(); }; return (
{/* Date Picker */}
{ handleDateChange(value.month, value.day, value.year); }} width="100%" height={250} style={{ position: "relative", display: "flex", backgroundColor: "var(--secondary-background)", overflow: "hidden", width: "100%", height: 250, border: "1px solid var(--border)", borderRadius: "8px", }} aria-selected={false} > {pickerOptions.month.map((option) => ( {({ selected }) => (
{option.label}
)}
))}
{pickerOptions.day.map((option) => ( {({ selected }) => (
{option.label}
)}
))}
{pickerOptions.year.map((option) => ( {({ selected }) => (
{option.label}
)}
))}
); }