'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

exports['default'] = generatePicker;

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _icon = require('../../icon');

var _icon2 = _interopRequireDefault(_icon);

var _rcPicker = require('rc-picker');

var _rcPicker2 = _interopRequireDefault(_rcPicker);

var _en_US = require('../locale/en_US');

var _en_US2 = _interopRequireDefault(_en_US);

var _util = require('../util');

var _warning = require('antd/lib/_util/warning');

var _warning2 = _interopRequireDefault(_warning);

var _context = require('antd/lib/config-provider/context');

var _LocaleReceiver = require('antd/lib/locale-provider/LocaleReceiver');

var _LocaleReceiver2 = _interopRequireDefault(_LocaleReceiver);

var _pagePoint = require('../../page-point');

var _pagePoint2 = _interopRequireDefault(_pagePoint);

var _ = require('.');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var __rest = undefined && undefined.__rest || function (s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
};
var sendPagePoint = _pagePoint2['default'].sendPagePoint,
    regKey = _pagePoint2['default'].pagePointConfig.regKey,
    clickType = _pagePoint2['default'].EventType.clickType;
function generatePicker(generateConfig) {
    function getPicker(picker, displayName) {
        var Picker = function (_React$Component) {
            (0, _inherits3['default'])(Picker, _React$Component);

            function Picker(props) {
                (0, _classCallCheck3['default'])(this, Picker);

                var _this = (0, _possibleConstructorReturn3['default'])(this, (Picker.__proto__ || Object.getPrototypeOf(Picker)).call(this, props));

                _this.pickerRef = React.createRef();
                _this.focus = function () {
                    if (_this.pickerRef.current) {
                        _this.pickerRef.current.focus();
                    }
                };
                _this.blur = function () {
                    if (_this.pickerRef.current) {
                        _this.pickerRef.current.blur();
                    }
                };
                _this.getDefaultLocale = function () {
                    var locale = _this.props.locale;

                    var result = (0, _extends3['default'])((0, _extends3['default'])({}, _en_US2['default']), locale);
                    result.lang = (0, _extends3['default'])((0, _extends3['default'])({}, result.lang), (locale || {}).lang);
                    return result;
                };
                _this.renderPicker = function (locale) {
                    var _classNames;

                    var _this$context = _this.context,
                        getPrefixCls = _this$context.getPrefixCls,
                        getPopupContainer = _this$context.getPopupContainer,
                        pagePoint = _this$context.pagePoint;
                    var _a = _this.props,
                        customizePrefixCls = _a.prefixCls,
                        customizeGetPopupContainer = _a.getPopupContainer,
                        getCalendarContainer = _a.getCalendarContainer,
                        monthCellContentRender = _a.monthCellContentRender,
                        customizeMonthCellRender = _a.monthCellRender,
                        className = _a.className,
                        onChange = _a.onChange,
                        customizeSize = _a.size,
                        _a$bordered = _a.bordered,
                        bordered = _a$bordered === undefined ? true : _a$bordered,
                        placeholder = _a.placeholder,
                        showDateInput = _a.showDateInput,
                        inputReadOnly = _a.inputReadOnly,
                        _b = regKey,
                        dataRegId = _a[_b],
                        restProps = __rest(_a, ["prefixCls", "getPopupContainer", "getCalendarContainer", "monthCellContentRender", "monthCellRender", "className", "onChange", "size", "bordered", "placeholder", "showDateInput", "inputReadOnly", typeof _b === "symbol" ? _b : _b + ""]);var _this$props = _this.props,
                        format = _this$props.format,
                        showTime = _this$props.showTime;

                    var prefixCls = getPrefixCls('picker', customizePrefixCls);
                    var additionalProps = {
                        showToday: true
                    };
                    var newChange = onChange;
                    if (pagePoint && dataRegId) {
                        newChange = function newChange(dateMomnet, dateString) {
                            var _sendPagePoint;

                            onChange && onChange(dateMomnet, dateString);
                            var dateStr = dateString;
                            // rangepicker为数组
                            if (Array.isArray(dateString)) {
                                dateStr = JSON.stringify(dateString);
                            }
                            // change 发送 click
                            sendPagePoint((_sendPagePoint = {
                                eventType: clickType,
                                tagname: "datetimePicker",
                                value: dateStr
                            }, (0, _defineProperty3['default'])(_sendPagePoint, regKey, dataRegId), (0, _defineProperty3['default'])(_sendPagePoint, 'origValue', _this.origValue), _sendPagePoint));
                            _this.origValue = dateStr;
                        };
                    }
                    var inputRO = showDateInput === false ? inputReadOnly || true : inputReadOnly;
                    var additionalOverrideProps = {};
                    if (picker) {
                        additionalOverrideProps.picker = picker;
                    }
                    var mergedPicker = picker || _this.props.picker;
                    additionalOverrideProps = (0, _extends3['default'])((0, _extends3['default'])((0, _extends3['default'])({}, additionalOverrideProps), showTime ? (0, _.getTimeProps)((0, _extends3['default'])({ format: format, picker: mergedPicker }, showTime)) : {}), mergedPicker === 'time' ? (0, _.getTimeProps)((0, _extends3['default'])((0, _extends3['default'])({ format: format }, _this.props), { picker: mergedPicker })) : {});
                    var mergedSize = customizeSize;
                    return React.createElement(_rcPicker2['default'], (0, _extends3['default'])({ ref: _this.pickerRef, placeholder: (0, _util.getPlaceholder)(mergedPicker, locale, placeholder), suffixIcon: mergedPicker === 'time' ? React.createElement(_icon2['default'], { type: 'clock-circle' }) : React.createElement(_icon2['default'], { type: 'calendar' }), clearIcon: React.createElement(_icon2['default'], { type: 'close-circle' }), allowClear: true
                        //  transitionName="slide-up"
                    }, additionalProps, restProps, additionalOverrideProps, { locale: locale.lang, className: (0, _classnames2['default'])(className, (_classNames = {}, (0, _defineProperty3['default'])(_classNames, prefixCls + '-' + mergedSize, mergedSize), (0, _defineProperty3['default'])(_classNames, prefixCls + '-borderless', !bordered), _classNames)), prefixCls: prefixCls, getPopupContainer: customizeGetPopupContainer || getCalendarContainer || getPopupContainer, monthCellRender: customizeMonthCellRender || monthCellContentRender, generateConfig: generateConfig, prevIcon: React.createElement('span', { className: prefixCls + '-prev-icon' }), nextIcon: React.createElement('span', { className: prefixCls + '-next-icon' }), superPrevIcon: React.createElement('span', { className: prefixCls + '-super-prev-icon' }), superNextIcon: React.createElement('span', { className: prefixCls + '-super-next-icon' }), components: _.Components, onChange: newChange, inputReadOnly: inputRO }));
                };
                (0, _warning2['default'])(picker !== 'quarter', displayName, 'DatePicker.' + displayName + ' is legacy usage. Please use DatePicker[picker=\'' + picker + '\'] directly.');
                return _this;
            }

            (0, _createClass3['default'])(Picker, [{
                key: 'render',
                value: function render() {
                    return React.createElement(
                        _LocaleReceiver2['default'],
                        { componentName: 'DatePicker', defaultLocale: this.getDefaultLocale },
                        this.renderPicker
                    );
                }
            }]);
            return Picker;
        }(React.Component);

        Picker.componentName = 'Picker';
        Picker.contextType = _context.ConfigContext;
        if (displayName) {
            Picker.displayName = displayName;
        }
        return Picker;
    }
    var DatePicker = getPicker();
    var WeekPicker = getPicker('week', 'WeekPicker');
    var MonthPicker = getPicker('month', 'MonthPicker');
    var YearPicker = getPicker('year', 'YearPicker');
    var TimePicker = getPicker('time', 'TimePicker');
    var QuarterPicker = getPicker('quarter', 'QuarterPicker');
    return { DatePicker: DatePicker, WeekPicker: WeekPicker, MonthPicker: MonthPicker, YearPicker: YearPicker, TimePicker: TimePicker, QuarterPicker: QuarterPicker };
}
module.exports = exports['default'];