'use client' import { Button } from '@/ui/components/ui/button' import { Calendar } from '@/ui/components/ui/calendar' import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover' import { ScrollArea, ScrollBar } from '@/ui/components/ui/scroll-area' import { Separator } from '@/ui/components/ui/separator' import { cn } from '@/ui/lib/utils' import { addHours, addWeeks, format } from 'date-fns' import { CalendarIcon } from 'lucide-react' import * as React from 'react' interface DateTimePickerProps { value?: Date onChange?: (date: Date | undefined) => void placeholder?: string disabled?: boolean className?: string } export function DateTimePicker({ value, onChange, placeholder = 'Pick a date', disabled, className, }: DateTimePickerProps) { const [isOpen, setIsOpen] = React.useState(false) const [tempValue, setTempValue] = React.useState(value) // Sync tempValue with value when popover opens React.useEffect(() => { if (isOpen) { setTempValue(value) } }, [isOpen, value]) const hours = Array.from({ length: 24 }, (_, i) => i) const minutes = Array.from({ length: 12 }, (_, i) => i * 5) // 5-minute increments const handleDateSelect = (selectedDate: Date | undefined) => { if (selectedDate) { const newDate = tempValue ? new Date(tempValue) : new Date() newDate.setFullYear(selectedDate.getFullYear()) newDate.setMonth(selectedDate.getMonth()) newDate.setDate(selectedDate.getDate()) setTempValue(newDate) } else { setTempValue(undefined) } } const handleTimeChange = (type: 'hour' | 'minute', timeValue: number) => { const newDate = tempValue ? new Date(tempValue) : new Date() if (type === 'hour') { newDate.setHours(timeValue) } else { newDate.setMinutes(timeValue) } setTempValue(newDate) } const handleQuickSelect = (type: '24h' | '1w' | '2w') => { let newDate = new Date() if (type === '24h') { newDate = addHours(newDate, 24) } else if (type === '1w') { newDate = addWeeks(newDate, 1) } else if (type === '2w') { newDate = addWeeks(newDate, 2) } setTempValue(newDate) } const handleSave = () => { onChange?.(tempValue) setIsOpen(false) } return (
{/* Hours Column */}
{hours.map((hour) => ( ))}
{/* Minutes Column */}
{minutes.map((minute) => ( ))}
) }