import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import { __decorate } from "tslib";
import React from 'react';
import moment from 'moment';
import noop from 'lodash/noop';
import classNames from 'classnames';
import DaysView, { alwaysValidDate } from './DaysView';
import TimesView from './TimesView';
import autobind from '../_util/autobind';
import { ViewMode } from './enum';
import { FieldType } from '../data-set/enum';
import { $l } from '../locale-context';
import { getDateFormatByFieldType } from '../field/utils';

var DateTimesView = /*#__PURE__*/function (_DaysView) {
  _inherits(DateTimesView, _DaysView);

  var _super = _createSuper(DateTimesView);

  function DateTimesView() {
    var _this;

    _classCallCheck(this, DateTimesView);

    _this = _super.apply(this, arguments);

    _this.getTimeProps = function () {
      var _this$props$format = _this.props.format,
          format = _this$props$format === void 0 ? getDateFormatByFieldType(TimesView.type) : _this$props$format;

      var timeProps = _objectSpread(_objectSpread({}, _this.props), {}, {
        mode: ViewMode.time,
        datetimeSide: true,
        format: format,
        renderExtraFooter: undefined
      });

      return timeProps;
    };

    return _this;
  }

  _createClass(DateTimesView, [{
    key: "getViewClassName",
    value: function getViewClassName() {
      var prefixCls = this.prefixCls;
      return "".concat(prefixCls, "-datetime");
    }
  }, {
    key: "handleTimeSelect",
    value: function handleTimeSelect() {
      this.changeViewMode(ViewMode.time);
    }
  }, {
    key: "handleCellClick",
    value: function handleCellClick(date) {
      this.changeSelectedDate(date);
    }
  }, {
    key: "handleKeyDownRight",
    value: function handleKeyDownRight(e) {
      if (e.altKey) {
        this.changeViewMode(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 : _this$props$onSelect,
          selectedDate = _this$props.date,
          _this$props$isValidDa = _this$props.isValidDate,
          isValidDate = _this$props$isValidDa === void 0 ? alwaysValidDate : _this$props$isValidDa;
      var selected = selectedDate.clone();

      if (isValidDate(date, selected) && isValidDate(date, selected, 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: classNames("".concat(prefixCls, "-footer-now-btn"), _defineProperty({}, "".concat(prefixCls, "-now-disabled"), disabledNow)),
        onClick: !disabledNow ? this.choose.bind(this, moment(), false) : noop
      };
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-footer")
      }, /*#__PURE__*/React.createElement("a", _extends({}, footerProps), $l('DatePicker', 'now')), okButton && /*#__PURE__*/React.createElement("a", {
        className: "".concat(prefixCls, "-footer-view-select"),
        onClick: this.choose.bind(this, this.props.date, false)
      }, $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 = classNames("".concat(prefixCls, "-view"), className, this.getViewClassName());
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
        className: "".concat(this.getViewClassName(), "-wrapper")
      }, /*#__PURE__*/React.createElement("div", {
        className: classString
      }, this.renderHeader(), this.renderBody()), /*#__PURE__*/React.createElement(TimesView, _extends({}, this.getTimeProps()))), extraFooterPlacement === 'top' && this.customFooter, this.renderFooter(), extraFooterPlacement === 'bottom' && this.customFooter);
    }
  }]);

  return DateTimesView;
}(DaysView);

export { DateTimesView as default };
DateTimesView.displayName = 'DateTimesView';
DateTimesView.type = FieldType.dateTime;

__decorate([autobind], DateTimesView.prototype, "handleTimeSelect", null);
//# sourceMappingURL=DateTimesView.js.map
