'use client';
import { CalendarIcon } from 'lucide-react';
import React from 'react';
import {
DatePicker as AriaDatePicker,
DatePickerProps as AriaDatePickerProps,
DateValue,
ValidationResult
} from 'react-aria-components';
import { Calendar } from '@/registry/react-aria/ui/Calendar';
import { DateInput } from '@/registry/react-aria/ui/DateField';
import { Description, FieldError, FieldGroup, Label } from '@/registry/react-aria/ui/Field';
import { Popover } from '@/registry/react-aria/ui/Popover';
import { composeTailwindRenderProps } from '@/registry/react-aria/lib/react-aria-utils';
import { FieldButton } from '@/registry/react-aria/ui/FieldButton';
export interface DatePickerProps<T extends DateValue>
extends AriaDatePickerProps<T> {
label?: string;
description?: string;
errorMessage?: string | ((validation: ValidationResult) => string);
}
export function DatePicker<T extends DateValue>(
{ label, description, errorMessage, ...props }: DatePickerProps<T>
) {
return (
<AriaDatePicker {...props} className={composeTailwindRenderProps(props.className, 'group flex flex-col gap-1 font-sans')}>
{label && <Label>{label}</Label>}
<FieldGroup className="min-w-[208px] w-auto cursor-text disabled:cursor-default">
<DateInput className="flex-1 min-w-[150px] px-3 text-sm" />
<FieldButton className="w-6 mr-1 outline-offset-0">
<CalendarIcon aria-hidden className="w-4 h-4" />
</FieldButton>
</FieldGroup>
{description && <Description>{description}</Description>}
<FieldError>{errorMessage}</FieldError>
<Popover className="p-2">
<Calendar />
</Popover>
</AriaDatePicker>
);
}