var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { forwardRef, useMemo, } from 'react';
import { DatePicker as FusionDatePicker } from '@alifd/next';
import moment from 'moment';
import hoist from '../../utils/hoist';
var RangePicker = FusionDatePicker.RangePicker;
export function withDefaultFormat(WrappedComponent) {
    // eslint-disable-next-line react/display-name
    var Wrapper = forwardRef(function (props, ref) {
        var _a;
        var defaultFormat = useMemo(function () {
            return moment().localeData().longDateFormat('ll'); // 从全局 moment 对象获取当前的 moment 文案
        }, []);
        // 从props的moment对象获取当前的moment文案
        var value = props.value, defaultValue = props.defaultValue;
        var exactValue = value || defaultValue;
        if (moment.isMoment(exactValue)) {
            defaultFormat = exactValue.localeData().longDateFormat('ll');
        }
        var format = (_a = props.format) !== null && _a !== void 0 ? _a : defaultFormat;
        return React.createElement(WrappedComponent, __assign({}, props, { format: format, ref: ref }));
    });
    return hoist(Wrapper, WrappedComponent);
}
var DatePicker = withDefaultFormat(FusionDatePicker);
DatePicker.RangePicker = withDefaultFormat(RangePicker);
export var DatePickerRange = DatePicker.RangePicker;
export var DatePickerYear = DatePicker.YearPicker;
export var DatePickerMonth = DatePicker.MonthPicker;
export var DatePickerWeek = DatePicker.WeekPicker;
export default DatePicker;
