import { __assign, __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useCallback } from 'react';
import { I18nReceiver as Receiver } from '../i18n';
import SinglePicker from './components/SinglePickerBase';
import QuarterPanel from './panels/quarter-panel';
import PickerContext from './context/PickerContext';
import { DisabledContext } from '../disabled';
import { getCallbackValueRangeWithDate } from './utils/getValueInSinglePicker';
import { dateConfig } from './utils/dateUtils';
import { quarterFormatText } from './utils/formatInputText';
import { MONTH_FORMAT, defaultDatePickerCommonProps } from './constants';
var generateDate = dateConfig.quarter;
var PickerContextProvider = PickerContext.Provider;
var DefaultQuarterPickerProps = {
    format: MONTH_FORMAT,
};
export var QuarterPicker = function (props) {
    var disabledContext = useContext(DisabledContext);
    var propsRequired = __assign(__assign(__assign({}, defaultDatePickerCommonProps), DefaultQuarterPickerProps), props);
    var value = propsRequired.value, defaultDate = propsRequired.defaultDate, _a = propsRequired.disabled, disabled = _a === void 0 ? disabledContext.value : _a, placeholder = propsRequired.placeholder, restProps = __rest(propsRequired, ["value", "defaultDate", "disabled", "placeholder"]);
    var format = restProps.format, valueType = restProps.valueType;
    var getInputText = useCallback(function (i18n) { return function (val) { return quarterFormatText(val, i18n); }; }, []);
    var getSelectedValue = useCallback(function (val) { return val; }, []);
    var getCallbackValue = useCallback(function (val) {
        return getCallbackValueRangeWithDate(val, valueType, format, generateDate);
    }, [valueType, format]);
    return (_jsx(Receiver, __assign({ componentName: "TimePicker" }, { children: function (i18n) { return (_jsx(PickerContextProvider, __assign({ value: {
                i18n: i18n,
                generateDate: generateDate,
                getCallbackValue: getCallbackValue,
                getSelectedValue: getSelectedValue,
                getInputText: getInputText(i18n),
            } }, { children: _jsx(SinglePicker, __assign({}, restProps, { value: Array.isArray(value) ? value[0] : value, defaultDate: Array.isArray(defaultDate) ? defaultDate[0] : defaultDate, disabled: disabled, placeholder: placeholder || i18n.quarter, PanelComponent: QuarterPanel }), void 0) }), void 0)); } }), void 0));
};
export default QuarterPicker;
