import { __assign } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useCallback } from 'react';
import { I18nReceiver as Receiver } from '../i18n';
import CombinedPicker from './components/CombinedPickerBase';
import CombinedDatePanel from './panels/combined-date-range-panel';
import { DisabledContext } from '../disabled';
import PickerContext from './context/PickerContext';
import { dateConfig } from './utils/dateUtils';
import { formatTextRange } from './utils/formatInputText';
import { INPUT_WIDTH, COMBINED_INPUT_WIDTH, DATE_FORMAT, defaultDatePickerCommonProps, } from './constants';
var generateDate = dateConfig.date;
var PickerContextProvider = PickerContext.Provider;
var DefaultCombinedDateRangeProps = {
    format: DATE_FORMAT,
};
export var CombinedDateRangePicker = function (props) {
    var disabledContext = useContext(DisabledContext);
    var propsRequired = __assign(__assign(__assign({}, defaultDatePickerCommonProps), DefaultCombinedDateRangeProps), props);
    var placeholder = propsRequired.placeholder, format = propsRequired.format, width = propsRequired.width, showTime = propsRequired.showTime, _a = propsRequired.disabled, disabled = _a === void 0 ? disabledContext.value : _a;
    var getInputRangeText = useCallback(function (val) { return formatTextRange(val, format); }, [format]);
    return (_jsx(Receiver, __assign({ componentName: "TimePicker" }, { children: function (i18n) { return (_jsx(PickerContextProvider, __assign({ value: { i18n: i18n, autoComplete: !!showTime, getInputRangeText: getInputRangeText } }, { children: _jsx(CombinedPicker, __assign({}, propsRequired, { width: width !== null && width !== void 0 ? width : (!!showTime ? COMBINED_INPUT_WIDTH : INPUT_WIDTH), disabled: disabled, generateDate: generateDate, seperator: i18n.to, placeholder: placeholder || [i18n.start, i18n.end], PanelComponent: CombinedDatePanel }), void 0) }), void 0)); } }), void 0));
};
export default CombinedDateRangePicker;
