import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 classNames from 'classnames';
import autobind from '../_util/autobind';
import Icon from '../icon';
import DaysView, { alwaysValidDate } from './DaysView';
import { ViewMode } from './enum';
import { stopEvent } from '../_util/EventManager';

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

  var _super = _createSuper(DecadeYearsView);

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

    return _super.apply(this, arguments);
  }

  _createClass(DecadeYearsView, [{
    key: "getViewClassName",
    value: function getViewClassName() {
      var prefixCls = this.prefixCls;
      return "".concat(prefixCls, "-decade-year");
    }
  }, {
    key: "handlePrevYearClick",
    value: function handlePrevYearClick() {
      this.changeCursorDate(this.getCloneDate().subtract(100, 'y'));
    }
  }, {
    key: "handleNextYearClick",
    value: function handleNextYearClick() {
      this.changeCursorDate(this.getCloneDate().add(100, 'y'));
    }
  }, {
    key: "handleKeyDownHome",
    value: function handleKeyDownHome(e) {
      stopEvent(e);
      var date = this.getCloneDate();
      this.changeCursorDate(date.subtract(date.year() % 100, 'y'));
    }
  }, {
    key: "handleKeyDownEnd",
    value: function handleKeyDownEnd(e) {
      stopEvent(e);
      var date = this.getCloneDate();
      this.changeCursorDate(date.add(90 - date.year() % 100, 'y'));
    }
  }, {
    key: "handleKeyDownLeft",
    value: function handleKeyDownLeft(e) {
      stopEvent(e);

      if (!e.altKey) {
        this.changeCursorDate(this.getCloneDate().subtract(10, 'y'));
      }
    }
  }, {
    key: "handleKeyDownRight",
    value: function handleKeyDownRight(e) {
      stopEvent(e);

      if (e.altKey) {
        this.changeViewMode(ViewMode.year);
      } else {
        this.changeCursorDate(this.getCloneDate().add(10, 'y'));
      }
    }
  }, {
    key: "handleKeyDownUp",
    value: function handleKeyDownUp(e) {
      stopEvent(e);
      this.changeCursorDate(this.getCloneDate().subtract(30, 'y'));
    }
  }, {
    key: "handleKeyDownDown",
    value: function handleKeyDownDown(e) {
      stopEvent(e);
      this.changeCursorDate(this.getCloneDate().add(30, 'y'));
    }
  }, {
    key: "handleKeyDownPageUp",
    value: function handleKeyDownPageUp(e) {
      stopEvent(e);
      this.changeCursorDate(this.getCloneDate().subtract(100, 'y'));
    }
  }, {
    key: "handleKeyDownPageDown",
    value: function handleKeyDownPageDown(e) {
      stopEvent(e);
      this.changeCursorDate(this.getCloneDate().add(100, 'y'));
    }
  }, {
    key: "renderHeader",
    value: function renderHeader() {
      var prefixCls = this.prefixCls,
          date = this.props.date;
      var year = date.year() % 100;
      var from = date.clone().subtract(year, 'y');
      var to = from.clone().add(99, 'y');
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-header")
      }, /*#__PURE__*/React.createElement("a", {
        className: "".concat(prefixCls, "-prev-year"),
        onClick: this.handlePrevYearClick
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "first_page"
      })), /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-view-select")
      }, from.year(), " - ", to.year()), /*#__PURE__*/React.createElement("a", {
        className: "".concat(prefixCls, "-next-year")
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "last_page",
        onClick: this.handleNextYearClick
      })));
    }
  }, {
    key: "renderPanelHead",
    value: function renderPanelHead() {
      return undefined;
    }
  }, {
    key: "renderPanelBody",
    value: function renderPanelBody() {
      var prefixCls = this.prefixCls,
          _this$props = this.props,
          date = _this$props.date,
          _this$props$renderer = _this$props.renderer,
          renderer = _this$props$renderer === void 0 ? this.renderCell : _this$props$renderer,
          _this$props$isValidDa = _this$props.isValidDate,
          isValidDate = _this$props$isValidDa === void 0 ? alwaysValidDate : _this$props$isValidDa,
          onDateMouseLeave = _this$props.onDateMouseLeave;
      var selected = date.clone().subtract(date.year() % 10, 'y');
      var from = date.clone().startOf('y').subtract(date.year() % 100, 'y');
      var to = from.clone().add(100, 'y');
      var prevYear = from.clone().subtract(10, 'y');
      var lastYear = to.clone().add(10, 'y');
      var rows = [];
      var cells = [];

      while (prevYear.isBefore(lastYear)) {
        var _classNames;

        var currentYear = prevYear.clone();
        var isDisabled = !isValidDate(currentYear, selected);
        var className = classNames("".concat(prefixCls, "-cell"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-old"), currentYear.isBefore(from, 'y')), _defineProperty(_classNames, "".concat(prefixCls, "-new"), currentYear.isSame(to, 'y')), _defineProperty(_classNames, "".concat(prefixCls, "-selected"), prevYear.isSame(selected, 'y')), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), isDisabled), _classNames));
        var text = "".concat(prevYear.year(), "-").concat(prevYear.clone().add(9, 'y').year());
        var decadeProps = {
          key: text,
          className: className,
          children: this.renderInner(text)
        };

        if (!isDisabled) {
          decadeProps.onClick = this.handleCellClick.bind(this, currentYear);
          decadeProps.onMouseEnter = this.handleDateMouseEnter.bind(this, currentYear);
          decadeProps.onMouseLeave = onDateMouseLeave;
        }

        cells.push(renderer(decadeProps, text, currentYear, selected));

        if (cells.length === 3) {
          rows.push( /*#__PURE__*/React.createElement("tr", {
            key: text
          }, cells));
          cells = [];
        }

        prevYear.add(10, 'y');
      }

      return rows;
    }
  }, {
    key: "renderFooter",
    value: function renderFooter() {
      return undefined;
    }
  }, {
    key: "getPanelClass",
    value: function getPanelClass() {
      return "".concat(this.prefixCls, "-year-panel");
    }
  }, {
    key: "choose",
    value: function choose(date) {
      this.changeCursorDate(date);
      this.changeViewMode(ViewMode.year);
    }
  }]);

  return DecadeYearsView;
}(DaysView);

export { DecadeYearsView as default };
DecadeYearsView.displayName = 'DecadeYearView';

__decorate([autobind], DecadeYearsView.prototype, "handlePrevYearClick", null);

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