function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import moment from 'moment';
import Overlay from '../overlay';
import Input from '../input';
import Icon from '../icon';
import RangeCalendar from '../calendar/range-calendar';
import TimePickerPanel from '../time-picker/panel';
import nextLocale from '../locale/zh-cn';
import { func, obj } from '../util';
import { PANEL, resetValueTime, formatDateValue, extend, getDateTimeFormat, isFunction, onDateKeydown, onTimeKeydown } from './util';
import PanelFooter from './module/panel-footer';
var Popup = Overlay.Popup;

function mapInputStateName(name) {
  return {
    startValue: 'startDateInputStr',
    endValue: 'endDateInputStr',
    startTime: 'startTimeInputStr',
    endTime: 'endTimeInputStr'
  }[name];
}

function mapTimeToValue(name) {
  return {
    startTime: 'startValue',
    endTime: 'endValue'
  }[name];
}

function getFormatValues(values, format) {
  if (!Array.isArray(values)) {
    return [null, null];
  }

  return [formatDateValue(values[0], format), formatDateValue(values[1], format)];
}
/**
 * DatePicker.RangePicker
 */


var RangePicker =
/*#__PURE__*/
function (_Component) {
  _inherits(RangePicker, _Component);

  function RangePicker(props, context) {
    var _this;

    _classCallCheck(this, RangePicker);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(RangePicker).call(this, props, context));

    _defineProperty(_assertThisInitialized(_this), "getOverlay", function () {
      return _this.popup && _this.popup.getInstance() && _this.popup.getInstance().getOverlay();
    });

    _defineProperty(_assertThisInitialized(_this), "onValueChange", function (values) {
      var handler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'onChange';
      var ret;

      if (!values.length || !_this.inputAsString) {
        ret = values;
      } else {
        ret = [values[0] ? values[0].format(_this.dateTimeFormat) : null, values[1] ? values[1].format(_this.dateTimeFormat) : null];
      }

      _this.props[handler](ret);
    });

    _defineProperty(_assertThisInitialized(_this), "onSelectCalendarPanel", function (value) {
      var _this$props = _this.props,
          showTime = _this$props.showTime,
          resetTime = _this$props.resetTime;
      var _this$state = _this.state,
          prevActiveDateInput = _this$state.activeDateInput,
          prevStartValue = _this$state.startValue,
          prevEndValue = _this$state.endValue;
      var newState = {
        activeDateInput: prevActiveDateInput,
        inputing: false
      };
      var newValue = value;

      switch (prevActiveDateInput) {
        case 'startValue':
          {
            if (!prevEndValue || value.valueOf() <= prevEndValue.valueOf()) {
              newState.activeDateInput = 'endValue';
            }

            if (showTime) {
              if (!prevStartValue) {
                // 第一次选择，如果设置了时间默认值，则使用该默认时间
                if (showTime.defaultValue) {
                  var defaultTimeValue = formatDateValue(showTime.defaultValue, _this.timeFormat);
                  newValue = resetValueTime(value, defaultTimeValue);
                }
              } else if (!resetTime) {
                // 非第一次选择，如果开启了 resetTime ，则记住之前选择的时间值
                newValue = resetValueTime(value, prevStartValue);
              }
            }

            newState.startValue = newValue;

            if (prevEndValue && value.valueOf() > prevEndValue.valueOf()) {
              newState.endValue = null;
              newState.activeDateInput = 'endValue';
            }

            break;
          }

        case 'endValue':
          if (!prevStartValue) {
            newState.activeDateInput = 'startValue';
          }

          if (showTime) {
            if (!prevEndValue) {
              // 第一次选择，如果设置了时间默认值，则使用该默认时间
              if (showTime.defaultValue) {
                var _defaultTimeValue = formatDateValue(showTime.defaultValue, _this.timeFormat);

                newValue = resetValueTime(value, _defaultTimeValue);
              }
            } else if (!resetTime) {
              // 非第一次选择，如果开启了 resetTime ，则记住之前选择的时间值
              newValue = resetValueTime(value, prevEndValue);
            }
          }

          newState.endValue = newValue; // 选择了一个比开始日期更小的结束日期，此时表示用户重新选择了

          if (prevStartValue && value.valueOf() < prevStartValue.valueOf()) {
            newState.startValue = value;
            newState.endValue = null;
          }

          break;
      }

      var newStartValue = 'startValue' in newState ? newState.startValue : prevStartValue;
      var newEndValue = 'endValue' in newState ? newState.endValue : prevEndValue; // 受控状态选择不更新值

      if ('value' in _this.props) {
        delete newState.startValue;
        delete newState.endValue;
      }

      _this.setState(newState);

      _this.onValueChange([newStartValue, newEndValue]);
    });

    _defineProperty(_assertThisInitialized(_this), "clearRange", function () {
      _this.setState({
        startDateInputStr: '',
        endDateInputStr: '',
        startTimeInputStr: '',
        endTimeInputStr: ''
      });

      if (!('value' in _this.props)) {
        _this.setState({
          startValue: null,
          endValue: null
        });
      }

      _this.onValueChange([]);
    });

    _defineProperty(_assertThisInitialized(_this), "onDateInputChange", function (inputStr, e, eventType) {
      if (eventType === 'clear' || !inputStr) {
        e.stopPropagation();

        _this.clearRange();
      } else {
        var _this$setState;

        var stateName = mapInputStateName(_this.state.activeDateInput);

        _this.setState((_this$setState = {}, _defineProperty(_this$setState, stateName, inputStr), _defineProperty(_this$setState, "inputing", _this.state.activeDateInput), _this$setState));
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onDateInputBlur", function () {
      var stateName = mapInputStateName(_this.state.activeDateInput);
      var dateInputStr = _this.state[stateName];

      if (dateInputStr) {
        var _this$setState2;

        var _this$props2 = _this.props,
            format = _this$props2.format,
            disabledDate = _this$props2.disabledDate;
        var parsed = moment(dateInputStr, format, true);

        _this.setState((_this$setState2 = {}, _defineProperty(_this$setState2, stateName, ''), _defineProperty(_this$setState2, "inputing", false), _this$setState2));

        if (parsed.isValid() && !disabledDate(parsed, 'date')) {
          var valueName = _this.state.activeDateInput;
          var newValue = parsed;

          _this.handleChange(valueName, newValue);
        }
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onDateInputKeyDown", function (e) {
      var activeDateInput = _this.state.activeDateInput;
      var stateName = mapInputStateName(activeDateInput);
      var dateInputStr = _this.state[stateName];
      var format = _this.props.format;
      var dateStr = onDateKeydown(e, {
        format: format,
        value: _this.state[activeDateInput],
        dateInputStr: dateInputStr
      }, 'day');
      if (!dateStr) return;
      return _this.onDateInputChange(dateStr);
    });

    _defineProperty(_assertThisInitialized(_this), "onFocusDateInput", function (type) {
      if (type !== _this.state.activeDateInput) {
        _this.setState({
          activeDateInput: type
        });
      }

      if (_this.state.panel !== PANEL.DATE) {
        _this.setState({
          panel: PANEL.DATE
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onFocusTimeInput", function (type) {
      if (type !== _this.state.activeDateInput) {
        _this.setState({
          activeDateInput: type
        });
      }

      if (_this.state.panel !== PANEL.TIME) {
        _this.setState({
          panel: PANEL.TIME
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onSelectStartTime", function (value) {
      if (!('value' in _this.props)) {
        _this.setState({
          startValue: value,
          inputing: false,
          activeDateInput: 'startTime'
        });
      }

      if (value.valueOf() !== _this.state.startValue.valueOf()) {
        _this.onValueChange([value, _this.state.endValue]);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onSelectEndTime", function (value) {
      if (!('value' in _this.props)) {
        _this.setState({
          endValue: value,
          inputing: false,
          activeDateInput: 'endTime'
        });
      }

      if (value.valueOf() !== _this.state.endValue.valueOf()) {
        _this.onValueChange([_this.state.startValue, value]);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onTimeInputChange", function (inputStr) {
      var _this$setState3;

      var stateName = mapInputStateName(_this.state.activeDateInput);

      _this.setState((_this$setState3 = {}, _defineProperty(_this$setState3, stateName, inputStr), _defineProperty(_this$setState3, "inputing", _this.state.activeDateInput), _this$setState3));
    });

    _defineProperty(_assertThisInitialized(_this), "onTimeInputBlur", function () {
      var stateName = mapInputStateName(_this.state.activeDateInput);
      var timeInputStr = _this.state[stateName];

      if (timeInputStr) {
        var _this$setState4;

        var parsed = moment(timeInputStr, _this.timeFormat, true);

        _this.setState((_this$setState4 = {}, _defineProperty(_this$setState4, stateName, ''), _defineProperty(_this$setState4, "inputing", false), _this$setState4));

        if (parsed.isValid()) {
          var hour = parsed.hour();
          var minute = parsed.minute();
          var second = parsed.second();
          var valueName = mapTimeToValue(_this.state.activeDateInput);

          var newValue = _this.state[valueName].clone().hour(hour).minute(minute).second(second);

          _this.handleChange(valueName, newValue);
        }
      }
    });

    _defineProperty(_assertThisInitialized(_this), "onTimeInputKeyDown", function (e) {
      var showTime = _this.props.showTime;
      var activeDateInput = _this.state.activeDateInput;
      var stateName = mapInputStateName(activeDateInput);
      var timeInputStr = _this.state[stateName];

      var _ref = _typeof(showTime) === 'object' ? showTime : {},
          disabledMinutes = _ref.disabledMinutes,
          disabledSeconds = _ref.disabledSeconds,
          _ref$hourStep = _ref.hourStep,
          hourStep = _ref$hourStep === void 0 ? 1 : _ref$hourStep,
          _ref$minuteStep = _ref.minuteStep,
          minuteStep = _ref$minuteStep === void 0 ? 1 : _ref$minuteStep,
          _ref$secondStep = _ref.secondStep,
          secondStep = _ref$secondStep === void 0 ? 1 : _ref$secondStep;

      var unit = 'second';

      if (disabledSeconds) {
        unit = disabledMinutes ? 'hour' : 'minute';
      }

      var timeStr = onTimeKeydown(e, {
        format: _this.timeFormat,
        timeInputStr: timeInputStr,
        value: _this.state[activeDateInput.indexOf('start') ? 'startValue' : 'endValue'],
        steps: {
          hour: hourStep,
          minute: minuteStep,
          second: secondStep
        }
      }, unit);
      if (!timeStr) return;

      _this.onTimeInputChange(timeStr);
    });

    _defineProperty(_assertThisInitialized(_this), "handleChange", function (valueName, newValue) {
      if (!('value' in _this.props)) {
        _this.setState(_defineProperty({}, valueName, newValue));
      }

      var startValue = valueName === 'startValue' ? newValue : _this.state.startValue;
      var endValue = valueName === 'endValue' ? newValue : _this.state.endValue;

      _this.onValueChange([startValue, endValue]);
    });

    _defineProperty(_assertThisInitialized(_this), "onVisibleChange", function (visible, type) {
      if (!('visible' in _this.props)) {
        _this.setState({
          visible: visible
        });
      }

      _this.props.onVisibleChange(visible, type);
    });

    _defineProperty(_assertThisInitialized(_this), "changePanel", function (panel) {
      _this.setState({
        panel: panel,
        activeDateInput: panel === PANEL.DATE ? 'startValue' : 'startTime'
      });
    });

    _defineProperty(_assertThisInitialized(_this), "onOk", function () {
      _this.onVisibleChange(false, 'okBtnClick');

      _this.onValueChange([_this.state.startValue, _this.state.endValue], 'onOk');
    });

    _defineProperty(_assertThisInitialized(_this), "getDisabledTime", function (_ref2) {
      var startValue = _ref2.startValue,
          endValue = _ref2.endValue;

      var _ref3 = _this.props.showTime || {},
          disabledHours = _ref3.disabledHours,
          disabledMinutes = _ref3.disabledMinutes,
          disabledSeconds = _ref3.disabledSeconds;

      var disabledTime = {};

      if (startValue && endValue) {
        var isSameDay = startValue.format('L') === endValue.format('L');
        var newDisabledHours = isFunction(disabledHours) ? disabledHours : function (index) {
          if (isSameDay && index < startValue.hour()) {
            return true;
          }
        };
        var newDisabledMinutes = isFunction(disabledMinutes) ? disabledMinutes : function (index) {
          if (isSameDay && startValue.hour() === endValue.hour() && index < startValue.minute()) {
            return true;
          }
        };
        var newDisabledSeconds = isFunction(disabledSeconds) ? disabledSeconds : function (index) {
          if (isSameDay && startValue.hour() === endValue.hour() && startValue.minute() === endValue.minute() && index <= startValue.second()) {
            return true;
          }
        };
        disabledTime = {
          disabledHours: newDisabledHours,
          disabledMinutes: newDisabledMinutes,
          disabledSeconds: newDisabledSeconds
        };
      }

      return disabledTime;
    });

    var dateTimeFormat = getDateTimeFormat(props.format, props.showTime);
    extend(dateTimeFormat, _assertThisInitialized(_this));
    var val = props.value || props.defaultValue;

    var _values = getFormatValues(val, _this.dateTimeFormat);

    _this.inputAsString = val && (typeof val[0] === 'string' || typeof val[1] === 'string');
    _this.state = {
      visible: props.visible || props.defaultVisible,
      startValue: _values[0],
      endValue: _values[1],
      startDateInputStr: '',
      endDateInputStr: '',
      activeDateInput: 'startValue',
      startTimeInputStr: '',
      endTimeInputStr: '',
      inputing: false,
      // 当前是否处于输入状态
      panel: PANEL.DATE
    };
    _this.popup = null;
    return _this;
  }

  _createClass(RangePicker, [{
    key: "UNSAFE_componentWillReceiveProps",
    value: function UNSAFE_componentWillReceiveProps(nextProps) {
      if ('showTime' in nextProps) {
        var dateTimeFormat = getDateTimeFormat(nextProps.format || this.props.format, nextProps.showTime);
        extend(dateTimeFormat, this);
      }

      if ('value' in nextProps) {
        var values = getFormatValues(nextProps.value, this.dateTimeFormat);
        this.setState({
          startValue: values[0],
          endValue: values[1]
        });
        this.inputAsString = nextProps.value && (typeof nextProps.value[0] === 'string' || typeof nextProps.value[1] === 'string');
      }

      if ('visible' in nextProps) {
        this.setState({
          visible: nextProps.visible
        });
      }
    } // 获取底层的overlay实例

  }, {
    key: "render",
    value: function render() {
      var _classnames,
          _classnames2,
          _classnames3,
          _classnames4,
          _classnames5,
          _this2 = this,
          _PANEL$DATE$PANEL$TIM;

      var _this$props3 = this.props,
          prefix = _this$props3.prefix,
          rtl = _this$props3.rtl,
          defaultVisibleMonth = _this$props3.defaultVisibleMonth,
          onVisibleMonthChange = _this$props3.onVisibleMonthChange,
          showTime = _this$props3.showTime,
          disabledDate = _this$props3.disabledDate,
          footerRender = _this$props3.footerRender,
          label = _this$props3.label,
          _this$props3$ranges = _this$props3.ranges,
          ranges = _this$props3$ranges === void 0 ? {} : _this$props3$ranges,
          inputState = _this$props3.state,
          size = _this$props3.size,
          disabled = _this$props3.disabled,
          hasClear = _this$props3.hasClear,
          popupTriggerType = _this$props3.popupTriggerType,
          popupAlign = _this$props3.popupAlign,
          popupContainer = _this$props3.popupContainer,
          popupStyle = _this$props3.popupStyle,
          popupClassName = _this$props3.popupClassName,
          popupProps = _this$props3.popupProps,
          followTrigger = _this$props3.followTrigger,
          className = _this$props3.className,
          locale = _this$props3.locale,
          inputProps = _this$props3.inputProps,
          triggerRender = _this$props3.triggerRender,
          dateCellRender = _this$props3.dateCellRender,
          monthCellRender = _this$props3.monthCellRender,
          yearCellRender = _this$props3.yearCellRender,
          startDateInputAriaLabel = _this$props3.startDateInputAriaLabel,
          startTimeInputAriaLabel = _this$props3.startTimeInputAriaLabel,
          endDateInputAriaLabel = _this$props3.endDateInputAriaLabel,
          endTimeInputAriaLabel = _this$props3.endTimeInputAriaLabel,
          inline = _this$props3.inline,
          others = _objectWithoutProperties(_this$props3, ["prefix", "rtl", "defaultVisibleMonth", "onVisibleMonthChange", "showTime", "disabledDate", "footerRender", "label", "ranges", "state", "size", "disabled", "hasClear", "popupTriggerType", "popupAlign", "popupContainer", "popupStyle", "popupClassName", "popupProps", "followTrigger", "className", "locale", "inputProps", "triggerRender", "dateCellRender", "monthCellRender", "yearCellRender", "startDateInputAriaLabel", "startTimeInputAriaLabel", "endDateInputAriaLabel", "endTimeInputAriaLabel", "inline"]);

      var state = this.state;
      var classNames = classnames((_classnames = {}, _defineProperty(_classnames, "".concat(prefix, "range-picker"), true), _defineProperty(_classnames, "".concat(prefix).concat(size), size), _defineProperty(_classnames, "".concat(prefix, "disabled"), disabled), _classnames), className);
      var panelBodyClassName = classnames((_classnames2 = {}, _defineProperty(_classnames2, "".concat(prefix, "range-picker-body"), true), _defineProperty(_classnames2, "".concat(prefix, "range-picker-inline"), inline), _defineProperty(_classnames2, "".concat(prefix, "range-picker-body-show-time"), showTime), _classnames2));
      var triggerCls = classnames((_classnames3 = {}, _defineProperty(_classnames3, "".concat(prefix, "range-picker-trigger"), true), _defineProperty(_classnames3, "".concat(prefix, "error"), inputState === 'error'), _classnames3));
      var startDateInputCls = classnames((_classnames4 = {}, _defineProperty(_classnames4, "".concat(prefix, "range-picker-panel-input-start-date"), true), _defineProperty(_classnames4, "".concat(prefix, "focus"), state.activeDateInput === 'startValue'), _classnames4));
      var endDateInputCls = classnames((_classnames5 = {}, _defineProperty(_classnames5, "".concat(prefix, "range-picker-panel-input-end-date"), true), _defineProperty(_classnames5, "".concat(prefix, "focus"), state.activeDateInput === 'endValue'), _classnames5));

      if (rtl) {
        others.dir = 'rtl';
      }

      var startDateInputValue = state.inputing === 'startValue' ? state.startDateInputStr : state.startValue && state.startValue.format(this.format) || '';
      var endDateInputValue = state.inputing === 'endValue' ? state.endDateInputStr : state.endValue && state.endValue.format(this.format) || '';
      var startTriggerValue = startDateInputValue;
      var endTriggerValue = endDateInputValue;

      var sharedInputProps = _objectSpread({}, inputProps, {
        size: size,
        disabled: disabled,
        onChange: this.onDateInputChange,
        onBlur: this.onDateInputBlur,
        onPressEnter: this.onDateInputBlur,
        onKeyDown: this.onDateInputKeyDown
      });

      var startDateInput = React.createElement(Input, _extends({}, sharedInputProps, {
        hasClear: true,
        size: "xs",
        "aria-label": startDateInputAriaLabel,
        placeholder: this.format,
        value: startDateInputValue,
        onFocus: function onFocus() {
          return _this2.onFocusDateInput('startValue');
        },
        className: startDateInputCls
      }));
      var endDateInput = React.createElement(Input, _extends({}, sharedInputProps, {
        hasClear: true,
        size: "xs",
        "aria-label": endDateInputAriaLabel,
        placeholder: this.format,
        value: endDateInputValue,
        onFocus: function onFocus() {
          return _this2.onFocusDateInput('endValue');
        },
        className: endDateInputCls
      }));
      var datePanel = React.createElement(RangeCalendar, {
        showOtherMonth: true,
        dateCellRender: dateCellRender,
        monthCellRender: monthCellRender,
        yearCellRender: yearCellRender,
        format: this.format,
        defaultVisibleMonth: defaultVisibleMonth,
        onVisibleMonthChange: onVisibleMonthChange,
        disabledDate: disabledDate,
        onSelect: this.onSelectCalendarPanel,
        startValue: state.startValue,
        endValue: state.endValue
      });
      var startTimeInput = null;
      var endTimeInput = null;
      var timePanel = null;
      var panelFooter = footerRender();

      if (showTime) {
        var _classnames6, _classnames7;

        var startTimeInputValue = state.inputing === 'startTime' ? state.startTimeInputStr : state.startValue && state.startValue.format(this.timeFormat) || '';
        var endTimeInputValue = state.inputing === 'endTime' ? state.endTimeInputStr : state.endValue && state.endValue.format(this.timeFormat) || '';
        startTriggerValue = state.startValue && state.startValue.format(this.dateTimeFormat) || '';
        endTriggerValue = state.endValue && state.endValue.format(this.dateTimeFormat) || '';
        var sharedTimeInputProps = {
          size: size,
          placeholder: this.timeFormat,
          onFocus: this.onFocusTimeInput,
          onBlur: this.onTimeInputBlur,
          onPressEnter: this.onTimeInputBlur,
          onChange: this.onTimeInputChange,
          onKeyDown: this.onTimeInputKeyDown
        };
        var startTimeInputCls = classnames((_classnames6 = {}, _defineProperty(_classnames6, "".concat(prefix, "range-picker-panel-input-start-time"), true), _defineProperty(_classnames6, "".concat(prefix, "focus"), state.activeDateInput === 'startTime'), _classnames6));
        startTimeInput = React.createElement(Input, _extends({}, sharedTimeInputProps, {
          size: "xs",
          value: startTimeInputValue,
          "aria-label": startTimeInputAriaLabel,
          disabled: disabled || !state.startValue || !state.endValue,
          onFocus: function onFocus() {
            return _this2.onFocusTimeInput('startTime');
          },
          className: startTimeInputCls
        }));
        var endTimeInputCls = classnames((_classnames7 = {}, _defineProperty(_classnames7, "".concat(prefix, "range-picker-panel-input-end-time"), true), _defineProperty(_classnames7, "".concat(prefix, "focus"), state.activeDateInput === 'endTime'), _classnames7));
        endTimeInput = React.createElement(Input, _extends({}, sharedTimeInputProps, {
          size: "xs",
          value: endTimeInputValue,
          "aria-label": endTimeInputAriaLabel,
          disabled: disabled || !state.endValue || !state.startValue,
          onFocus: function onFocus() {
            return _this2.onFocusTimeInput('endTime');
          },
          className: endTimeInputCls
        }));
        var showSecond = this.timeFormat.indexOf('s') > -1;

        var sharedTimePickerProps = _objectSpread({}, showTime, {
          prefix: prefix,
          locale: locale,
          disabled: disabled,
          showSecond: showSecond
        });

        var disabledTime = this.getDisabledTime(state);
        timePanel = React.createElement("div", {
          className: "".concat(prefix, "range-picker-panel-time")
        }, React.createElement(TimePickerPanel, _extends({}, sharedTimePickerProps, {
          className: "".concat(prefix, "range-picker-panel-time-start"),
          value: state.startValue,
          onSelect: this.onSelectStartTime
        })), React.createElement(TimePickerPanel, _extends({}, sharedTimePickerProps, disabledTime, {
          className: "".concat(prefix, "range-picker-panel-time-end"),
          value: state.endValue,
          onSelect: this.onSelectEndTime
        })));
      }

      panelFooter = panelFooter || React.createElement(PanelFooter, {
        prefix: prefix,
        value: state.startValue && state.endValue,
        ranges: Object.keys(ranges).map(function (key) {
          return {
            label: key,
            value: ranges[key],
            onChange: function onChange(values) {
              _this2.setState({
                startValue: values[0],
                endValue: values[1]
              });

              _this2.onValueChange(values);
            }
          };
        }),
        disabledOk: !state.startValue || !state.endValue || state.startValue.valueOf() > state.endValue.valueOf(),
        locale: locale,
        panel: state.panel,
        onPanelChange: showTime ? this.changePanel : null,
        onOk: this.onOk
      });
      var panelBody = (_PANEL$DATE$PANEL$TIM = {}, _defineProperty(_PANEL$DATE$PANEL$TIM, PANEL.DATE, datePanel), _defineProperty(_PANEL$DATE$PANEL$TIM, PANEL.TIME, timePanel), _PANEL$DATE$PANEL$TIM)[state.panel];
      var allowClear = state.startValue && state.endValue && hasClear;
      var trigger = triggerRender ? triggerRender([state.startValue, state.endValue], {
        popupVisible: state.visible
      }) : React.createElement("div", {
        className: triggerCls
      }, React.createElement(Input, _extends({}, sharedInputProps, {
        readOnly: true,
        role: "combobox",
        "aria-expanded": state.visible,
        label: label,
        placeholder: locale.startPlaceholder,
        value: startTriggerValue,
        hasBorder: false,
        className: "".concat(prefix, "range-picker-trigger-input"),
        onFocus: function onFocus() {
          return _this2.onFocusDateInput('startValue');
        }
      })), React.createElement("span", {
        className: "".concat(prefix, "range-picker-trigger-separator")
      }, "~"), React.createElement(Input, _extends({}, sharedInputProps, {
        readOnly: true,
        role: "combobox",
        "aria-expanded": state.visible,
        placeholder: locale.endPlaceholder,
        value: endTriggerValue,
        hasBorder: false,
        className: "".concat(prefix, "range-picker-trigger-input"),
        onFocus: function onFocus() {
          return _this2.onFocusDateInput('endValue');
        },
        hasClear: allowClear
      })), React.createElement(Icon, {
        type: "calendar",
        className: "".concat(prefix, "range-picker-trigger-icon")
      }));
      var body = React.createElement("div", {
        dir: others.dir,
        className: panelBodyClassName
      }, React.createElement("div", {
        className: "".concat(prefix, "range-picker-panel-header")
      }, React.createElement("div", {
        className: "".concat(prefix, "range-picker-panel-input")
      }, startDateInput, startTimeInput, React.createElement("span", {
        className: "".concat(prefix, "range-picker-panel-input-separator")
      }, "~"), endDateInput, endTimeInput)), panelBody, panelFooter);
      return inline ? body : React.createElement("div", _extends({}, obj.pickOthers(RangePicker.propTypes, others), {
        className: classNames
      }), React.createElement(Popup, _extends({
        offset: [0, 4]
      }, popupProps, {
        followTrigger: followTrigger,
        autoFocus: true,
        ref: function ref(popup) {
          _this2.popup = popup;
        },
        disabled: disabled,
        visible: state.visible,
        onVisibleChange: this.onVisibleChange,
        align: popupAlign,
        triggerType: popupTriggerType,
        container: popupContainer,
        style: popupStyle,
        className: popupClassName,
        trigger: trigger
      }), body));
    }
  }]);

  return RangePicker;
}(Component);

_defineProperty(RangePicker, "propTypes", {
  prefix: PropTypes.string,
  rtl: PropTypes.bool,

  /**
   * 默认展示的起始月份
   * @return {MomentObject} 返回包含指定月份的 moment 对象实例
   */
  defaultVisibleMonth: PropTypes.func,
  onVisibleMonthChange: PropTypes.func,

  /**
   * 日期范围值数组 [moment, moment]
   */
  value: PropTypes.array,

  /**
   * 初始的日期范围值数组 [moment, moment]
   */
  defaultValue: PropTypes.array,

  /**
   * 日期格式
   */
  format: PropTypes.string,

  /**
   * 是否使用时间控件，支持传入 TimePicker 的属性
   */
  showTime: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),

  /**
   * 每次选择是否重置时间（仅在 showTime 开启时有效）
   */
  resetTime: PropTypes.bool,

  /**
   * 禁用日期函数
   * @param {MomentObject} 日期值
   * @param {String} view 当前视图类型，year: 年， month: 月, date: 日
   * @return {Boolean} 是否禁用
   */
  disabledDate: PropTypes.func,

  /**
   * 自定义面板页脚
   * @return {Node} 自定义的面板页脚组件
   */
  footerRender: PropTypes.func,

  /**
   * 日期范围值改变时的回调 [ MomentObject|String, MomentObject|String ]
   * @param {Array<MomentObject|String>} value 日期值
   */
  onChange: PropTypes.func,

  /**
   * 点击确认按钮时的回调 返回开始时间和结束时间`[ MomentObject|String, MomentObject|String ]`
   * @return {Array} 日期范围
   */
  onOk: PropTypes.func,

  /**
   * 输入框内置标签
   */
  label: PropTypes.node,

  /**
   * 输入框状态
   */
  state: PropTypes.oneOf(['error', 'loading', 'success']),

  /**
   * 输入框尺寸
   */
  size: PropTypes.oneOf(['small', 'medium']),

  /**
   * 是否禁用
   */
  disabled: PropTypes.bool,

  /**
   * 是否显示清空按钮
   */
  hasClear: PropTypes.bool,

  /**
   * 弹层显示状态
   */
  visible: PropTypes.bool,

  /**
   * 弹层默认是否显示
   */
  defaultVisible: PropTypes.bool,

  /**
   * 弹层展示状态变化时的回调
   * @param {Boolean} visible 弹层是否显示
   * @param {String} type 触发弹层显示和隐藏的来源 okBtnClick 表示由确认按钮触发； fromTrigger 表示由trigger的点击触发； docClick 表示由document的点击触发
   */
  onVisibleChange: PropTypes.func,

  /**
   * 弹层触发方式
   */
  popupTriggerType: PropTypes.oneOf(['click', 'hover']),

  /**
   * 弹层对齐方式, 具体含义见 OverLay文档
   */
  popupAlign: PropTypes.string,

  /**
   * 弹层容器
   * @param {Element} target 目标元素
   * @return {Element} 弹层的容器元素
   */
  popupContainer: PropTypes.func,

  /**
   * 弹层自定义样式
   */
  popupStyle: PropTypes.object,

  /**
   * 弹层自定义样式类
   */
  popupClassName: PropTypes.string,

  /**
   * 弹层其他属性
   */
  popupProps: PropTypes.object,

  /**
   * 是否跟随滚动
   */
  followTrigger: PropTypes.bool,

  /**
   * 输入框其他属性
   */
  inputProps: PropTypes.object,

  /**
   * 自定义触发器
   * @param {Array} value 日期值（moment对象)数组
   * @param {Object} state 附加状态
   * @returns {ReactNode}
   */
  triggerRender: PropTypes.func,

  /**
   * 自定义日期单元格渲染
   */
  dateCellRender: PropTypes.func,

  /**
   * 自定义月份渲染函数
   * @param {Object} calendarDate 对应 Calendar 返回的自定义日期对象
   * @returns {ReactNode}
   */
  monthCellRender: PropTypes.func,
  yearCellRender: PropTypes.func,
  // 兼容 0.x yearCellRender

  /**
   * 开始日期输入框的 aria-label 属性
   */
  startDateInputAriaLabel: PropTypes.string,

  /**
   * 开始时间输入框的 aria-label 属性
   */
  startTimeInputAriaLabel: PropTypes.string,

  /**
   * 结束日期输入框的 aria-label 属性
   */
  endDateInputAriaLabel: PropTypes.string,

  /**
   * 结束时间输入框的 aria-label 属性
   */
  endTimeInputAriaLabel: PropTypes.string,
  ranges: PropTypes.object,
  locale: PropTypes.object,
  className: PropTypes.string,

  /**
   * 是否开启行内模式
   */
  inline: PropTypes.bool
});

_defineProperty(RangePicker, "defaultProps", {
  prefix: 'next-',
  rtl: false,
  format: 'YYYY/MM/DD',
  size: 'medium',
  showTime: false,
  resetTime: false,
  disabledDate: function disabledDate() {
    return false;
  },
  footerRender: function footerRender() {
    return null;
  },
  hasClear: true,
  defaultVisible: false,
  popupTriggerType: 'click',
  popupAlign: 'tl bl',
  locale: nextLocale.DatePicker,
  onChange: func.noop,
  onOk: func.noop,
  onVisibleChange: func.noop
});

export { RangePicker as default };