import { Button } from "antd"; import dayjs from "dayjs"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import Picker from "components/WheelPicker"; import { SERVER_DATE_FORMAT } from "utils/constants.ts"; interface PickupEstimateContentProps { onSave: (date: string, time: string) => void; onClose: () => void; } export default function PickupEstimateContent({ onSave, onClose, }: PickupEstimateContentProps) { const { t } = useTranslation(); // Generate day options: Today, Tomorrow, then formatted dates (90 days total for scrolling) const dayOptions = useMemo(() => { const options = []; const today = dayjs(); // Today options.push({ value: "today", label: "Today", date: today.format(SERVER_DATE_FORMAT), }); // Tomorrow options.push({ value: "tomorrow", label: "Tomorrow", date: today.add(1, "day").format(SERVER_DATE_FORMAT), }); // Next days with formatted dates (up to 90 days total for smooth scrolling) for (let i = 2; i < 90; i++) { const date = today.add(i, "day"); const formatted = date.toDate().toLocaleDateString("en-US", { weekday: "long", month: "long", day: "numeric", }); options.push({ value: `day-${i}`, label: formatted, date: date.format(SERVER_DATE_FORMAT), }); } return options; }, []); // Generate time options: Now, then time slots (5 items total) const timeOptions = useMemo(() => { const options = []; const now = dayjs(); // Now option options.push({ value: "now", label: "Now", time: now.format("HH:mm"), }); // Calculate next 15-minute interval (always the next one, even if we're on a boundary) const currentMinute = now.minute(); let nextMinute = Math.floor(currentMinute / 15) * 15 + 15; let nextHour = now.hour(); if (nextMinute >= 60) { nextMinute = 0; nextHour += 1; if (nextHour >= 24) { nextHour = 0; } } // Generate next 4 time slots (15-minute intervals) let hour = nextHour; let minute = nextMinute; for (let i = 0; i < 96; i++) { const time = dayjs().hour(hour).minute(minute).second(0); const formatted = time.format("h:mm A"); options.push({ value: `time-${i}`, label: formatted, time: time.format("HH:mm"), }); // Calculate next interval minute += 15; if (minute >= 60) { minute = 0; hour += 1; if (hour >= 24) { hour = 0; } } } return options; }, []); const [selectedDay, setSelectedDay] = useState("today"); const [selectedTime, setSelectedTime] = useState("now"); const handlePickerChange = (value: { day?: string; time?: string }) => { console.log(value); if (value.day !== undefined) { setSelectedDay(value.day); } if (value.time !== undefined) { setSelectedTime(value.time); } }; const handleSave = () => { const selectedDayOption = dayOptions.find( (opt) => opt.value === selectedDay, ); const selectedTimeOption = timeOptions.find( (opt) => opt.value === selectedTime, ); if (selectedDayOption && selectedTimeOption) { onSave(selectedDayOption.date, selectedTimeOption.time); 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 ( <>
{/* Day and Time Pickers - Same Row */}
{/* Day Picker */}
handlePickerChange(value)} width="100%" height={250} style={{ position: "relative", display: "flex", backgroundColor: "var(--secondary-background)", overflow: "hidden", width: "100%", height: 250, border: "none", borderRadius: "8px", }} aria-selected={false} > {dayOptions.map((option) => ( {({ selected }) => (
{option.label}
)}
))}
{/* Time Picker */}
handlePickerChange(value)} width="100%" height={250} style={{ position: "relative", display: "flex", backgroundColor: "var(--secondary-background)", overflow: "hidden", width: "100%", height: 250, border: "none", borderRadius: "8px", }} aria-selected={false} > {timeOptions.map((option) => ( {({ selected }) => (
{option.label}
)}
))}
{/* Save Button */}
); }