function _typeof(obj) { 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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } 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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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); }

import React from 'react';
import classnames from 'classnames';
import Icon from '../../icon';
import { isDisabledDate, YEAR_TABLE_COL_COUNT, YEAR_TABLE_ROW_COUNT } from '../utils';

var YearTable =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(YearTable, _React$PureComponent);

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

    return _possibleConstructorReturn(this, _getPrototypeOf(YearTable).apply(this, arguments));
  }

  _createClass(YearTable, [{
    key: "onYearCellClick",
    value: function onYearCellClick(date) {
      this.props.onSelectYear(date, 'month');
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefix = _this$props.prefix,
          value = _this$props.value,
          today = _this$props.today,
          visibleMonth = _this$props.visibleMonth,
          disabledDate = _this$props.disabledDate,
          yearCellRender = _this$props.yearCellRender;
      var currentYear = today.year();
      var selectedYear = value ? value.year() : null;
      var visibleYear = visibleMonth.year();
      var startYear = Math.floor(visibleYear / 12) * 12;
      var yearElements = [];
      var counter = 0;

      for (var i = 0; i < YEAR_TABLE_ROW_COUNT; i++) {
        var rowElements = [];

        for (var j = 0; j < YEAR_TABLE_COL_COUNT; j++) {
          var _classnames;

          var isDisabled = false;
          var onClick = void 0;
          var year = startYear + counter++;
          var title = year;
          var yearDate = visibleMonth.clone().year(year);
          isDisabled = isDisabledDate(yearDate, disabledDate, 'year');
          !isDisabled && (onClick = this.onYearCellClick.bind(this, yearDate));
          var content = yearCellRender ? yearCellRender(yearDate) : year;
          var isSelected = year === selectedYear;
          var classNames = classnames((_classnames = {}, _defineProperty(_classnames, "".concat(prefix, "calendar-cell"), true), _defineProperty(_classnames, "".concat(prefix, "calendar-cell-current"), year === currentYear), _defineProperty(_classnames, "".concat(prefix, "selected"), isSelected), _defineProperty(_classnames, "".concat(prefix, "disabled"), isDisabled), _classnames));
          rowElements.push(React.createElement("td", {
            key: "".concat(i, "-").concat(j),
            className: classNames,
            role: "cell"
          }, React.createElement("div", {
            className: "".concat(prefix, "calendar-year"),
            onClick: onClick,
            title: title,
            "aria-disabled": isDisabled ? 'true' : 'false',
            "aria-selected": isSelected ? 'true' : 'false'
          }, content)));
        }

        yearElements.push(React.createElement("tr", {
          key: i,
          role: "row"
        }, rowElements));
      }

      return React.createElement("table", {
        className: "".concat(prefix, "calendar-table"),
        role: "grid"
      }, React.createElement("tbody", {
        className: "".concat(prefix, "calendar-tbody"),
        role: "rowgroup"
      }, yearElements));
    }
  }]);

  return YearTable;
}(React.PureComponent);

export default YearTable;