import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

/**
 * yearPanel.jsx
 *
 * @Author: apple
 * @Date: 2017/10/25 19:27
 */
import React, { Component } from 'react';
import classNames from 'classnames';
import moment from 'moment';
import Button from '../../button';
/**
 * @ignore
 * */

var YearPanel = /*#__PURE__*/function (_Component) {
  _inherits(YearPanel, _Component);

  var _super = _createSuper(YearPanel);

  function YearPanel() {
    var _this;

    _classCallCheck(this, YearPanel);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "handleSelect", function (value) {
      return function (e) {
        e.stopPropagation();
        var _this$props = _this.props,
            selectType = _this$props.selectType,
            onValueChange = _this$props.onValueChange,
            onPanelTypeChange = _this$props.onPanelTypeChange,
            onPanelDateChange = _this$props.onPanelDateChange;

        if (selectType === 'year') {
          onValueChange(value);
        } else {
          onPanelTypeChange('month');
        }

        onPanelDateChange(value);
      };
    });

    return _this;
  }

  _createClass(YearPanel, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props2 = this.props,
          value = _this$props2.value,
          panelDate = _this$props2.panelDate,
          disabledYear = _this$props2.disabledYear,
          prefixCls = _this$props2.prefixCls,
          rangeType = _this$props2.rangeType;
      var isRange = Array.isArray(value);
      var start = moment(panelDate).subtract(panelDate.year() % 10 + 1, 'year');
      return /*#__PURE__*/React.createElement("tbody", {
        className: "".concat(prefixCls, "-body")
      }, [0, 1, 2, 4].map(function (_, index) {
        return /*#__PURE__*/React.createElement("tr", {
          key: index
        }, [0, 1, 2].map(function (y, yearIndex) {
          var _classNames;

          var selected = false;
          var year = yearIndex + 3 * index;
          var item = moment(start).add(year, 'year');

          if (isRange && rangeType === 'start') {
            selected = value[0] && item.isSame(value[0], 'year');
          } else if (isRange && rangeType === 'end') {
            selected = value[1] && item.isSame(value[1], 'year');
          } else {
            selected = value && item.isSame(value, 'year');
          }

          var disabled = disabledYear && disabledYear(item);
          var classes = classNames("".concat(prefixCls, "-year-item"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-year-item-selected"), selected), _defineProperty(_classNames, "".concat(prefixCls, "-year-item-disabled"), disabled), _classNames));
          var cellClasses = classNames("".concat(prefixCls, "-year-cell"));
          return /*#__PURE__*/React.createElement("td", {
            key: year,
            className: cellClasses
          }, /*#__PURE__*/React.createElement(Button, {
            className: classes,
            onClick: _this2.handleSelect(item),
            disabled: disabled,
            shape: "none",
            type: year === 0 || year === 1 ? 'secondary' : null
          }, item.year()));
        }));
      }));
    }
  }]);

  return YearPanel;
}(Component);

_defineProperty(YearPanel, "propTypes", {});

_defineProperty(YearPanel, "defaultProps", {});

export default YearPanel;