import { jsx as _jsx } from "react/jsx-runtime";
import { DatePicker } from '../../components/DatePicker';
import { useFormContext } from '../useFormContext';
import { useFormFieldProps } from '../useFormFieldProps';
/**
 * DatePicker для формы. Инкапсулирует дефолтную валидацию на валидность даты
 */
export const FormDatePicker = ({ ...props }) => {
    const fieldProps = useFormFieldProps({
        ...props,
        defaultValue: props.defaultValue || null,
    });
    const { error, helperText, ...fieldPropsWithoutErrorProps } = fieldProps;
    const { trigger } = useFormContext();
    const { name, onBlur, onChange, ref, value, ...datePickerProps } = fieldPropsWithoutErrorProps;
    const handleDateChange = (date) => {
        onChange(date);
        trigger(name).catch();
    };
    return (_jsx(DatePicker, { ...fieldPropsWithoutErrorProps, inputProps: { ...datePickerProps.inputProps, error, helperText }, onChange: handleDateChange }));
};
