import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import React from 'react';
import classNames from 'classnames'; // import CalendarOutlined from '@ant-design/icons/CalendarOutlined';
// import ClockCircleOutlined from '@ant-design/icons/ClockCircleOutlined';
// import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
// import SwapRightOutlined from '@ant-design/icons/SwapRightOutlined';

import { RangePicker as RCRangePicker } from '../../components/rc-picker';
import zhCN from '../locale/zh_CN';
import { ConfigContext } from '../../config-provider/context'; // import LocaleReceiver from '../../locale-provider/LocaleReceiver';

import { getRangePlaceholder } from '../util';
import { getTimeProps, Components } from '.';
import Icon from '../../icon';
var CalenderLine = Icon.CalenderLine,
    TimeLine = Icon.TimeLine,
    CloseFill = Icon.CloseFill;
export default function generateRangePicker(generateConfig) {
  var RangePicker = /*#__PURE__*/function (_React$Component) {
    _inherits(RangePicker, _React$Component);

    var _super = _createSuper(RangePicker);

    function RangePicker() {
      var _this;

      _classCallCheck(this, RangePicker);

      _this = _super.apply(this, arguments);
      _this.pickerRef = /*#__PURE__*/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 = _objectSpread(_objectSpread({}, zhCN), locale);

        result.lang = _objectSpread(_objectSpread({}, result.lang), (locale || {}).lang);
        return result;
      };

      _this.renderPicker = function (locale) {
        var _classNames;

        var _this$context = _this.context,
            getPrefixClassName = _this$context.getPrefixClassName,
            getPopupContainer = _this$context.getPopupContainer,
            size = _this$context.size;

        var _this$props = _this.props,
            customizePrefixCls = _this$props.prefixCls,
            customGetPopupContainer = _this$props.getPopupContainer,
            className = _this$props.className,
            customizeSize = _this$props.size,
            _this$props$bordered = _this$props.bordered,
            bordered = _this$props$bordered === void 0 ? true : _this$props$bordered,
            placeholder = _this$props.placeholder,
            restProps = _objectWithoutProperties(_this$props, ["prefixCls", "getPopupContainer", "className", "size", "bordered", "placeholder"]);

        var _this$props2 = _this.props,
            format = _this$props2.format,
            showTime = _this$props2.showTime,
            picker = _this$props2.picker;
        var prefixCls = getPrefixClassName('picker', customizePrefixCls);
        var additionalOverrideProps = {};
        additionalOverrideProps = _objectSpread(_objectSpread(_objectSpread({}, additionalOverrideProps), showTime ? getTimeProps(_objectSpread({
          format: format,
          picker: picker
        }, showTime)) : {}), picker === 'time' ? getTimeProps(_objectSpread(_objectSpread({
          format: format
        }, _this.props), {}, {
          picker: picker
        })) : {});
        var rootPrefixCls = getPrefixClassName();
        var mergedSize = customizeSize || size;
        return (
          /*#__PURE__*/
          // <SizeContext.Consumer>
          //   {(size) => {
          //     const mergedSize = customizeSize || size;
          //     return (
          React.createElement(RCRangePicker, Object.assign({
            separator: /*#__PURE__*/React.createElement("span", {
              "aria-label": "to",
              className: "".concat(prefixCls, "-separator")
            }, "-"),
            ref: _this.pickerRef,
            placeholder: getRangePlaceholder(picker, locale, placeholder),
            suffixIcon: picker === 'time' ? /*#__PURE__*/React.createElement(TimeLine, null) : /*#__PURE__*/React.createElement(CalenderLine, null),
            clearIcon: /*#__PURE__*/React.createElement(CloseFill, null),
            allowClear: true,
            transitionName: "".concat(rootPrefixCls, "-slide-up")
          }, restProps, additionalOverrideProps, {
            className: classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(mergedSize), mergedSize), _defineProperty(_classNames, "".concat(prefixCls, "-borderless"), !bordered), _classNames), className),
            locale: locale.lang,
            prefixCls: prefixCls,
            getPopupContainer: customGetPopupContainer || getPopupContainer,
            generateConfig: generateConfig,
            prevIcon: /*#__PURE__*/React.createElement("span", {
              className: "".concat(prefixCls, "-prev-icon")
            }),
            nextIcon: /*#__PURE__*/React.createElement("span", {
              className: "".concat(prefixCls, "-next-icon")
            }),
            superPrevIcon: /*#__PURE__*/React.createElement("span", {
              className: "".concat(prefixCls, "-super-prev-icon")
            }),
            superNextIcon: /*#__PURE__*/React.createElement("span", {
              className: "".concat(prefixCls, "-super-next-icon")
            }),
            components: Components
          })) //   );
          // }}
          // </SizeContext.Consumer>

        );
      };

      return _this;
    }

    _createClass(RangePicker, [{
      key: "render",
      value: function render() {
        return (
          /*#__PURE__*/
          // <LocaleReceiver componentName="DatePicker" defaultLocale={this.getDefaultLocale}>
          React.createElement(React.Fragment, null, this.renderPicker(this.getDefaultLocale())) // </LocaleReceiver>

        );
      }
    }]);

    return RangePicker;
  }(React.Component);

  RangePicker.contextType = ConfigContext;
  RangePicker.displayName = 'RangePicker';
  return RangePicker;
}