'use client'; import type { BaseFormInputProps, WithPlaceholderProps } from '@/components/blocks/asset-form/asset-form-types'; import { getAriaAttributes } from '@/components/blocks/asset-form/asset-form-types'; import { Button } from '@/components/ui/button'; import { Calendar } from '@/components/ui/calendar'; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { formatDate } from '@/lib/date'; import { cn } from '@/lib/utils'; import { CalendarIcon } from '@radix-ui/react-icons'; import type { ComponentPropsWithoutRef } from 'react'; import type { FieldValues } from 'react-hook-form'; type CalendarProps = Omit, 'mode' | 'selected' | 'onSelect'>; type AssetFormDateProps = Omit> & BaseFormInputProps & WithPlaceholderProps & { /** Minimum selectable date */ fromDate?: Date; /** Maximum selectable date */ toDate?: Date; }; const DEFAULT_TO_DATE = new Date(new Date().setFullYear(new Date().getFullYear() + 10)); const DEFAULT_PLACEHOLDER = 'Pick a date'; /** * A form date input component that wraps shadcn's Calendar component with form field functionality. * Provides a date picker with optional min/max date constraints and full form integration. * * @example * ```tsx * * ``` */ export function AssetFormDate({ label, description, required, placeholder = DEFAULT_PLACEHOLDER, fromDate = new Date(), toDate = DEFAULT_TO_DATE, className, ...props }: AssetFormDateProps) { return ( { const ariaAttrs = getAriaAttributes(field.name, !!fieldState.error, props.disabled); return ( {label && ( {label} {required && *} )} date > toDate || date < fromDate} initialFocus /> {description && {description}} ); }} /> ); }