"use strict";

exports.__esModule = true;
exports.default = void 0;

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

var _calendar = _interopRequireDefault(require("../../calendar"));

var _utils = require("../../time-picker/utils");

var _basePicker = _interopRequireDefault(require("./base-picker"));

var _datePicker = _interopRequireDefault(require("../embed-picker/date-picker"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }

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

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

  function DatePicker() {
    return _BasePicker.apply(this, arguments) || this;
  }

  var _proto = DatePicker.prototype;

  _proto.renderPicker = function renderPicker() {
    var _this$props = this.props,
        showTime = _this$props.showTime,
        validRange = _this$props.validRange,
        mode = _this$props.mode;

    if (mode === 'picker') {
      return /*#__PURE__*/(0, _react.createElement)(_datePicker.default, {
        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__*/(0, _react.createElement)(_calendar.default, {
        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__*/(0, _react.createElement)(_calendar.default, {
        shape: "panel",
        mode: "month",
        enableYearPicker: true,
        value: this.state.pickerValue,
        disabledDate: this.props.disabledDate,
        validRange: this.props.validRange,
        onSelect: this.handleChange
      });
    }
  };

  _proto.getDefaultFormat = function getDefaultFormat() {
    return '';
  };

  _createClass(DatePicker, [{
    key: "timeFormat",
    get: function get() {
      var showTime = this.props.showTime;
      return typeof showTime === 'object' && showTime.format ? showTime.format : _utils.DEFAULT_FORMAT;
    }
  }, {
    key: "format",
    get: function get() {
      var showTime = this.props.showTime;
      var format = this.props.format || 'YYYY-MM-DD';
      return showTime ? format + " " + this.timeFormat : format;
    }
  }]);

  return DatePicker;
}(_basePicker.default);

exports.default = DatePicker;