"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _rcPicker = _interopRequireDefault(require("../../components/rc-picker"));

var _zh_CN = _interopRequireDefault(require("../locale/zh_CN"));

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

var _context = require("../../config-provider/context");

var _ = require(".");

var _icon = _interopRequireDefault(require("../../icon"));

// import CalendarOutlined from '@ant-design/icons/CalendarOutlined';
// import ClockCircleOutlined from '@ant-design/icons/ClockCircleOutlined';
// import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
var CalenderLine = _icon.default.CalenderLine,
    TimeLine = _icon.default.TimeLine,
    CloseFill = _icon.default.CloseFill;

function generatePicker(generateConfig) {
  function getPicker(picker, displayName) {
    var Picker = /*#__PURE__*/function (_React$Component) {
      (0, _inherits2.default)(Picker, _React$Component);

      var _super = (0, _createSuper2.default)(Picker);

      function Picker() {
        var _this;

        (0, _classCallCheck2.default)(this, Picker);
        _this = _super.apply(this, arguments);
        _this.pickerRef = /*#__PURE__*/_react.default.createRef(); // constructor(props: InnerPickerProps) {
        //   super(props);
        //   // devWarning(
        //   //   picker !== 'quarter',
        //   //   displayName!,
        //   //   `DatePicker.${displayName} is legacy usage. Please use DatePicker[picker='${picker}'] directly.`,
        //   // );
        // }

        _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, _objectSpread2.default)((0, _objectSpread2.default)({}, _zh_CN.default), locale);
          result.lang = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, 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,
              customizeGetPopupContainer = _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,
              pickWithTime = _this$props.pickWithTime,
              restProps = (0, _objectWithoutProperties2.default)(_this$props, ["prefixCls", "getPopupContainer", "className", "size", "bordered", "placeholder", "pickWithTime"]);
          var _this$props2 = _this.props,
              format = _this$props2.format,
              showTime = _this$props2.showTime;
          var prefixCls = getPrefixClassName('picker', customizePrefixCls);
          var additionalProps = {
            showToday: true
          };
          var additionalOverrideProps = {};

          if (picker) {
            additionalOverrideProps.picker = picker;
          }

          var mergedPicker = picker || _this.props.picker;
          additionalOverrideProps = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, additionalOverrideProps), showTime ? (0, _.getTimeProps)((0, _objectSpread2.default)({
            format: format,
            picker: mergedPicker
          }, showTime)) : {}), mergedPicker === 'time' ? (0, _.getTimeProps)((0, _objectSpread2.default)((0, _objectSpread2.default)({
            format: format
          }, _this.props), {}, {
            picker: mergedPicker
          })) : {});
          var rootPrefixCls = getPrefixClassName(); // return (
          //   <SizeContext.Consumer>
          //     {size => {
          //

          var mergedSize = customizeSize || size;
          return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_rcPicker.default, Object.assign({
            ref: _this.pickerRef,
            placeholder: (0, _util.getPlaceholder)(mergedPicker, locale, placeholder),
            suffixIcon: mergedPicker === 'time' ? /*#__PURE__*/_react.default.createElement(TimeLine, null) : /*#__PURE__*/_react.default.createElement(CalenderLine, null),
            clearIcon: /*#__PURE__*/_react.default.createElement(CloseFill, null),
            allowClear: true,
            transitionName: "".concat(rootPrefixCls, "-slide-up")
          }, additionalProps, restProps, additionalOverrideProps, {
            locale: locale.lang,
            className: (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-").concat(mergedSize), mergedSize), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-borderless"), !bordered), _classNames), className),
            prefixCls: prefixCls,
            getPopupContainer: customizeGetPopupContainer || getPopupContainer,
            generateConfig: generateConfig,
            prevIcon: /*#__PURE__*/_react.default.createElement("span", {
              className: "".concat(prefixCls, "-prev-icon")
            }),
            nextIcon: /*#__PURE__*/_react.default.createElement("span", {
              className: "".concat(prefixCls, "-next-icon")
            }),
            superPrevIcon: /*#__PURE__*/_react.default.createElement("span", {
              className: "".concat(prefixCls, "-super-prev-icon")
            }),
            superNextIcon: /*#__PURE__*/_react.default.createElement("span", {
              className: "".concat(prefixCls, "-super-next-icon")
            }),
            components: _.Components
          }))); //     }}
          //   </SizeContext.Consumer>
          // );
        };

        return _this;
      }

      (0, _createClass2.default)(Picker, [{
        key: "render",
        value: function render() {
          return (
            /*#__PURE__*/
            // <LocaleReceiver componentName="DatePicker" defaultLocale={this.getDefaultLocale}>
            _react.default.createElement(_react.default.Fragment, null, this.renderPicker(this.getDefaultLocale())) // </LocaleReceiver>

          );
        }
      }]);
      return Picker;
    }(_react.default.Component);

    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
  };
}