import { __assign, __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useMemo, useCallback } from 'react';
import { I18nReceiver as Receiver } from '../i18n';
import SinglePicker from './components/SinglePickerBase';
import WeekPanel from './panels/week-panel';
import PickerContext from './context/PickerContext';
import { DisabledContext } from '../disabled';
import { getSelectedValueWithDate, getCallbackValueRangeWithDate, } from './utils/getValueInSinglePicker';
import { dateConfig } from './utils/dateUtils';
import { weekFormatText } from './utils/formatInputText';
import { DATE_FORMAT, defaultDatePickerCommonProps } from './constants';
import { WeekStartsOnMap, } from './types';
var generateDate = dateConfig.week;
var PickerContextProvider = PickerContext.Provider;
export { WeekStartsOnMap };
var DefaultWeekPickerProps = {
    format: DATE_FORMAT,
    weekStartsOn: WeekStartsOnMap.Monday,
};
export var WeekPicker = function (props) {
    var disabledContext = useContext(DisabledContext);
    var propsRequired = __assign(__assign(__assign({}, defaultDatePickerCommonProps), DefaultWeekPickerProps), 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 weekStartsOn = restProps.weekStartsOn, format = restProps.format, valueType = restProps.valueType;
    var options = useMemo(function () { return ({ weekStartsOn: weekStartsOn }); }, [weekStartsOn]);
    var getInputText = useCallback(function (val) { return weekFormatText(val, format, options); }, [format, options]);
    var getSelectedValue = useCallback(function (val) { return getSelectedValueWithDate(val, generateDate, options); }, [options]);
    var getCallbackValue = useCallback(function (val) {
        return getCallbackValueRangeWithDate(val, valueType, format, generateDate, options);
    }, [valueType, format, options]);
    return (_jsx(Receiver, __assign({ componentName: "TimePicker" }, { children: function (i18n) { return (_jsx(PickerContextProvider, __assign({ value: {
                i18n: i18n,
                generateDate: generateDate,
                getCallbackValue: getCallbackValue,
                getSelectedValue: getSelectedValue,
                getInputText: getInputText,
            } }, { children: _jsx(SinglePicker, __assign({}, restProps, { value: Array.isArray(value) ? value[0] : value, defaultDate: Array.isArray(defaultDate) ? defaultDate[0] : defaultDate, disabled: disabled, seperator: i18n.to, placeholder: placeholder || i18n.week, PanelComponent: WeekPanel }), void 0) }), void 0)); } }), void 0));
};
export default WeekPicker;
