import * as React from 'react' import { format } from 'date-fns' import { CalendarIcon } from 'lucide-react' import { cn } from '@/lib/utils' import { Button } from './button' import { Calendar } from './calendar' import { Popover, PopoverContent, PopoverTrigger } from './popover' export interface DatePickerProps { value?: Date defaultValue?: Date onChange?: (date: Date | undefined) => void placeholder?: React.ReactNode disabled?: boolean className?: string align?: 'start' | 'center' | 'end' formatString?: string id?: string name?: string 'aria-label'?: string } function DatePicker({ value, defaultValue, onChange, placeholder = 'Pick a date', disabled, className, align = 'start', formatString = 'PPP', id, name, 'aria-label': ariaLabel, }: DatePickerProps) { const isControlled = value !== undefined const [internal, setInternal] = React.useState(defaultValue) const [open, setOpen] = React.useState(false) const selected = isControlled ? value : internal const handleSelect = React.useCallback( (next: Date | undefined) => { if (!isControlled) setInternal(next) onChange?.(next) if (next) setOpen(false) }, [isControlled, onChange], ) return ( {name ? ( ) : null} ) } export { DatePicker }