"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormDatePicker = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const DatePicker_1 = require("../../components/DatePicker");
const useFormContext_1 = require("../useFormContext");
const useFormFieldProps_1 = require("../useFormFieldProps");
/**
 * DatePicker для формы. Инкапсулирует дефолтную валидацию на валидность даты
 */
const FormDatePicker = ({ ...props }) => {
    const fieldProps = (0, useFormFieldProps_1.useFormFieldProps)({
        ...props,
        defaultValue: props.defaultValue || null,
    });
    const { error, helperText, ...fieldPropsWithoutErrorProps } = fieldProps;
    const { trigger } = (0, useFormContext_1.useFormContext)();
    const { name, onBlur, onChange, ref, value, ...datePickerProps } = fieldPropsWithoutErrorProps;
    const handleDateChange = (date) => {
        onChange(date);
        trigger(name).catch();
    };
    return ((0, jsx_runtime_1.jsx)(DatePicker_1.DatePicker, { ...fieldPropsWithoutErrorProps, inputProps: { ...datePickerProps.inputProps, error, helperText }, onChange: handleDateChange }));
};
exports.FormDatePicker = FormDatePicker;
