"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

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 _tslib = require("tslib");

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

var _moment = _interopRequireDefault(require("moment"));

var _noop = _interopRequireDefault(require("lodash/noop"));

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

var _DaysView2 = _interopRequireWildcard(require("./DaysView"));

var _TimesView = _interopRequireDefault(require("./TimesView"));

var _autobind = _interopRequireDefault(require("../_util/autobind"));

var _enum = require("./enum");

var _enum2 = require("../data-set/enum");

var _localeContext = require("../locale-context");

var _utils = require("../field/utils");

var DateTimesView = /*#__PURE__*/function (_DaysView) {
  (0, _inherits2["default"])(DateTimesView, _DaysView);

  var _super = (0, _createSuper2["default"])(DateTimesView);

  function DateTimesView() {
    var _this;

    (0, _classCallCheck2["default"])(this, DateTimesView);
    _this = _super.apply(this, arguments);

    _this.getTimeProps = function () {
      var _this$props$format = _this.props.format,
          format = _this$props$format === void 0 ? (0, _utils.getDateFormatByFieldType)(_TimesView["default"].type) : _this$props$format;
      var timeProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), {}, {
        mode: _enum.ViewMode.time,
        datetimeSide: true,
        format: format,
        renderExtraFooter: undefined
      });
      return timeProps;
    };

    return _this;
  }

  (0, _createClass2["default"])(DateTimesView, [{
    key: "getViewClassName",
    value: function getViewClassName() {
      var prefixCls = this.prefixCls;
      return "".concat(prefixCls, "-datetime");
    }
  }, {
    key: "handleTimeSelect",
    value: function handleTimeSelect() {
      this.changeViewMode(_enum.ViewMode.time);
    }
  }, {
    key: "handleCellClick",
    value: function handleCellClick(date) {
      this.changeSelectedDate(date);
    }
  }, {
    key: "handleKeyDownRight",
    value: function handleKeyDownRight(e) {
      if (e.altKey) {
        this.changeViewMode(_enum.ViewMode.time);
      } else {
        this.changeCursorDate(this.getCloneDate().add(1, 'd'));
      }
    }
  }, {
    key: "getFirstDay",
    value: function getFirstDay(date) {
      var firstDay = date.clone().subtract(1, 'M');
      var hour = firstDay.hour();
      var minute = firstDay.minute();
      var second = firstDay.second();
      firstDay.date(firstDay.daysInMonth()).startOf('w');
      firstDay.hour(hour);
      firstDay.minute(minute);
      firstDay.second(second);
      return firstDay;
    }
  }, {
    key: "choose",
    value: function choose(date) {
      var expand = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
      var _this$props = this.props,
          _this$props$onSelect = _this$props.onSelect,
          onSelect = _this$props$onSelect === void 0 ? _noop["default"] : _this$props$onSelect,
          selectedDate = _this$props.date,
          _this$props$isValidDa = _this$props.isValidDate,
          isValidDate = _this$props$isValidDa === void 0 ? _DaysView2.alwaysValidDate : _this$props$isValidDa;
      var selected = selectedDate.clone();

      if (isValidDate(date, selected) && isValidDate(date, selected, _enum.ViewMode.time)) {
        onSelect(date, expand);
      }
    }
  }, {
    key: "renderFooter",
    value: function renderFooter() {
      var prefixCls = this.prefixCls,
          _this$props2 = this.props,
          disabledNow = _this$props2.disabledNow,
          okButton = _this$props2.okButton;
      var footerProps = {
        className: (0, _classnames["default"])("".concat(prefixCls, "-footer-now-btn"), (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-now-disabled"), disabledNow)),
        onClick: !disabledNow ? this.choose.bind(this, (0, _moment["default"])(), false) : _noop["default"]
      };
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-footer")
      }, /*#__PURE__*/_react["default"].createElement("a", (0, _extends2["default"])({}, footerProps), (0, _localeContext.$l)('DatePicker', 'now')), okButton && /*#__PURE__*/_react["default"].createElement("a", {
        className: "".concat(prefixCls, "-footer-view-select"),
        onClick: this.choose.bind(this, this.props.date, false)
      }, (0, _localeContext.$l)('DatePicker', 'ok')));
    }
  }, {
    key: "render",
    value: function render() {
      var prefixCls = this.prefixCls,
          _this$props3 = this.props,
          className = _this$props3.className,
          extraFooterPlacement = _this$props3.extraFooterPlacement;
      var classString = (0, _classnames["default"])("".concat(prefixCls, "-view"), className, this.getViewClassName());
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(this.getViewClassName(), "-wrapper")
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: classString
      }, this.renderHeader(), this.renderBody()), /*#__PURE__*/_react["default"].createElement(_TimesView["default"], (0, _extends2["default"])({}, this.getTimeProps()))), extraFooterPlacement === 'top' && this.customFooter, this.renderFooter(), extraFooterPlacement === 'bottom' && this.customFooter);
    }
  }]);
  return DateTimesView;
}(_DaysView2["default"]);

exports["default"] = DateTimesView;
DateTimesView.displayName = 'DateTimesView';
DateTimesView.type = _enum2.FieldType.dateTime;
(0, _tslib.__decorate)([_autobind["default"]], DateTimesView.prototype, "handleTimeSelect", null);
//# sourceMappingURL=DateTimesView.js.map
