'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'] = generateRangePicker;

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 _en_US = require('../locale/en_US');

var _en_US2 = _interopRequireDefault(_en_US);

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

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

var _LocaleReceiver2 = _interopRequireDefault(_LocaleReceiver);

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

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 generateRangePicker(generateConfig) {
    var RangePicker = function (_React$Component) {
        (0, _inherits3['default'])(RangePicker, _React$Component);

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

            var _this = (0, _possibleConstructorReturn3['default'])(this, (RangePicker.__proto__ || Object.getPrototypeOf(RangePicker)).apply(this, arguments));

            _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,
                    customGetPopupContainer = _a.getPopupContainer,
                    getCalendarContainer = _a.getCalendarContainer,
                    monthCellContentRender = _a.monthCellContentRender,
                    customizeMonthCellRender = _a.monthCellRender,
                    className = _a.className,
                    customizeSize = _a.size,
                    onChange = _a.onChange,
                    _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", "size", "onChange", "bordered", "placeholder", "showDateInput", "inputReadOnly", typeof _b === "symbol" ? _b : _b + ""]);var _this$props = _this.props,
                    format = _this$props.format,
                    showTime = _this$props.showTime,
                    picker = _this$props.picker;

                var prefixCls = getPrefixCls('picker', customizePrefixCls);
                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 = {};
                additionalOverrideProps = (0, _extends3['default'])((0, _extends3['default'])((0, _extends3['default'])({}, additionalOverrideProps), showTime ? (0, _.getTimeProps)((0, _extends3['default'])({ format: format, picker: picker }, showTime)) : {}), picker === 'time' ? (0, _.getTimeProps)((0, _extends3['default'])((0, _extends3['default'])({ format: format }, _this.props), { picker: picker })) : {});
                var mergedSize = customizeSize;
                return React.createElement(_rcPicker.RangePicker, (0, _extends3['default'])({ separator: React.createElement(
                        'span',
                        { 'aria-label': 'to', className: prefixCls + '-separator' },
                        React.createElement(_icon2['default'], { type: 'swap-right' })
                    ), ref: _this.pickerRef, placeholder: (0, _util.getRangePlaceholder)(picker, locale, placeholder), suffixIcon: picker === '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"
                }, restProps, additionalOverrideProps, { className: (0, _classnames2['default'])(className, (_classNames = {}, (0, _defineProperty3['default'])(_classNames, prefixCls + '-' + mergedSize, mergedSize), (0, _defineProperty3['default'])(_classNames, prefixCls + '-borderless', !bordered), _classNames)), locale: locale.lang, prefixCls: prefixCls, getPopupContainer: customGetPopupContainer || 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 }));
            };
            return _this;
        }

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

    RangePicker.componentName = 'RangePicker';
    RangePicker.contextType = _context.ConfigContext;
    return RangePicker;
}
module.exports = exports['default'];