function _typeof(obj) { "@babel/helpers - typeof"; 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 _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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

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

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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

import React, { createElement } from "react";
import Calendar from '../../calendar';
import { DEFAULT_FORMAT } from '../../time-picker/utils';
import BasePicker from './base-picker';
import EmbedDatePicker from '../embed-picker/date-picker';

var DatePicker = /*#__PURE__*/function (_BasePicker) {
  _inherits(DatePicker, _BasePicker);

  var _super = _createSuper(DatePicker);

  function DatePicker() {
    _classCallCheck(this, DatePicker);

    return _super.apply(this, arguments);
  }

  _createClass(DatePicker, [{
    key: "renderPicker",
    value: function renderPicker() {
      var _this$props = this.props,
          showTime = _this$props.showTime,
          validRange = _this$props.validRange,
          mode = _this$props.mode;

      if (mode === 'picker') {
        return /*#__PURE__*/React.createElement(EmbedDatePicker, {
          value: this.state.pickerValue,
          disabledDate: this.props.disabledDate,
          validRange: validRange,
          onChange: this.handleChange
        });
      }

      if (showTime) {
        if (!validRange) {
          throw new Error('DatePicker with showTime must have validRange');
        }

        var format = showTime.format;
        return /*#__PURE__*/React.createElement(Calendar, {
          shape: "panel",
          mode: "month",
          enableYearPicker: true,
          enableTimePicker: true,
          timeFormat: format,
          value: this.state.pickerValue,
          disabledDate: this.props.disabledDate,
          validRange: validRange,
          onSelect: this.handleChange
        });
      } else {
        return /*#__PURE__*/React.createElement(Calendar, {
          shape: "panel",
          mode: "month",
          enableYearPicker: true,
          value: this.state.pickerValue,
          disabledDate: this.props.disabledDate,
          validRange: this.props.validRange,
          onSelect: this.handleChange
        });
      }
    }
  }, {
    key: "timeFormat",
    get: function get() {
      var showTime = this.props.showTime;
      return _typeof(showTime) === 'object' && showTime.format ? showTime.format : DEFAULT_FORMAT;
    }
  }, {
    key: "format",
    get: function get() {
      var showTime = this.props.showTime;
      var format = this.props.format || 'YYYY-MM-DD';
      return showTime ? "".concat(format, " ").concat(this.timeFormat) : format;
    }
  }, {
    key: "getDefaultFormat",
    value: function getDefaultFormat() {
      return '';
    }
  }]);

  return DatePicker;
}(BasePicker);

export { DatePicker as default };