"use client" import * as React from "react" import { format } from "date-fns" import { CalendarIcon } from "lucide-react" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Calendar } from "@/components/ui/calendar" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" interface DatePickerProps { value?: Date onChange?: (date: Date | undefined) => void placeholder?: string disabled?: boolean className?: string fromDate?: Date toDate?: Date } function DatePicker({ value, onChange, placeholder = "Pick a date", disabled = false, className, fromDate, toDate, }: DatePickerProps) { return ( } > {value ? format(value, "PPP") : placeholder} { if (fromDate && date < fromDate) return true if (toDate && date > toDate) return true return false }} autoFocus /> ) } interface DateRangePickerProps { value?: { from: Date | undefined; to?: Date | undefined } onChange?: (range: { from: Date | undefined; to?: Date | undefined } | undefined) => void placeholder?: string disabled?: boolean className?: string } function DateRangePicker({ value, onChange, placeholder = "Pick a date range", disabled = false, className, }: DateRangePickerProps) { return ( } > {value?.from ? ( value.to ? ( <> {format(value.from, "LLL dd, y")} –{" "} {format(value.to, "LLL dd, y")} ) : ( format(value.from, "LLL dd, y") ) ) : ( placeholder )} void} numberOfMonths={2} autoFocus /> ) } export { DatePicker, DateRangePicker }