import { __assign } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useCallback } from 'react';
import { I18nReceiver as Receiver } from '../i18n';
import DatePicker from './DatePicker';
import RangePicker from './components/RangePickerBase';
import { DisabledContext } from '../disabled';
import PickerContext from './context/PickerContext';
import { dateConfig } from './utils/dateUtils';
import { getRangeValuesWithValueType } from './utils/getValueInRangePicker';
import { INPUT_WIDTH, SINGLE_INPUT_WIDTH, DATE_FORMAT, defaultDatePickerCommonProps, } from './constants';
var generateDate = dateConfig.date;
var PickerContextProvider = PickerContext.Provider;
var DefaultDateRangeProps = {
    format: DATE_FORMAT,
};
export var DateRangePicker = function (props) {
    var disabledContext = useContext(DisabledContext);
    var propsRequired = __assign(__assign(__assign({}, defaultDatePickerCommonProps), DefaultDateRangeProps), props);
    var placeholder = propsRequired.placeholder, valueType = propsRequired.valueType, format = propsRequired.format, width = propsRequired.width, showTime = propsRequired.showTime, _a = propsRequired.disabled, disabled = _a === void 0 ? disabledContext.value : _a;
    var getCallbackRangeValue = useCallback(function (val) { return getRangeValuesWithValueType(valueType, format, val); }, [valueType, format]);
    return (_jsx(Receiver, __assign({ componentName: "TimePicker" }, { children: function (i18n) { return (_jsx(PickerContextProvider, __assign({ value: {
                i18n: i18n,
                autoComplete: !!showTime,
                getCallbackRangeValue: getCallbackRangeValue,
            } }, { children: _jsx(RangePicker, __assign({}, propsRequired, { disabled: disabled, width: width !== null && width !== void 0 ? width : (!!showTime ? INPUT_WIDTH : SINGLE_INPUT_WIDTH), generateDate: generateDate, seperator: i18n.to, placeholder: placeholder || [i18n.start, i18n.end], PickerComponent: DatePicker }), void 0) }), void 0)); } }), void 0));
};
export default DateRangePicker;
