"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormDateRangePicker = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const DateRangePicker_1 = require("../../components/DateRangePicker");
const useFormContext_1 = require("../useFormContext");
const useFormFieldProps_1 = require("../useFormFieldProps");
/**
 * DateRangePicker для формы. Инкапсулирует дефолтную валидацию на валидность даты
 */
const FormDateRangePicker = ({ startDateProps, endDateProps, ...props }) => {
    const { error, onChange, name, ...fieldProps } = (0, useFormFieldProps_1.useFormFieldProps)({
        ...props,
        defaultValue: props.defaultValue || null,
    });
    const { trigger } = (0, useFormContext_1.useFormContext)();
    const handleChange = (value) => {
        onChange(value);
        trigger(name).catch();
    };
    return ((0, jsx_runtime_1.jsx)(DateRangePicker_1.DateRangePicker, { isError: error, startDateProps: startDateProps, endDateProps: endDateProps, onChange: handleChange, ...fieldProps }));
};
exports.FormDateRangePicker = FormDateRangePicker;
