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

/**
 * monthPanel.jsx
 *
 * @Author: apple
 * @Date: 2017/10/25 19:28
 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import moment from 'moment';
import Button from '../../button';
var quarters = [0, 1, 2, 3];
var months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
/**
 * @ignore
 * */

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

  function MonthPanel() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, MonthPanel);

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

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MonthPanel)).call.apply(_getPrototypeOf2, [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 === 'month') {
          onValueChange(value);
        } else {
          onPanelTypeChange('date');
        }

        onPanelDateChange(value);
      };
    });

    return _this;
  }

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

      var _this$props2 = this.props,
          prefixCls = _this$props2.prefixCls,
          panelDate = _this$props2.panelDate,
          value = _this$props2.value,
          disabledMonth = _this$props2.disabledMonth,
          rangeType = _this$props2.rangeType;
      var isRange = Array.isArray(value);
      return React.createElement("tbody", {
        className: "".concat(prefixCls, "-body")
      }, quarters.map(function (_, index) {
        return React.createElement("tr", {
          key: index
        }, months.slice(3 * index, 3 * (1 + index)).map(function (monthLabel, monthIndex) {
          var _classNames;

          var selected = false;
          var month = monthIndex + 3 * index;
          var item = moment(panelDate).month(month);

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

          var disabled = disabledMonth && disabledMonth(item);
          var classes = classNames("".concat(prefixCls, "-month-item"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-month-item-selected"), selected), _defineProperty(_classNames, "".concat(prefixCls, "-month-item-disabled"), disabled), _classNames));
          var cellClasses = classNames("".concat(prefixCls, "-month-cell"));
          return React.createElement("td", {
            key: month,
            title: item.format('YYYY-MM'),
            className: cellClasses
          }, React.createElement(Button, {
            className: classes,
            onClick: _this2.handleSelect(item),
            disabled: disabled,
            shape: "none"
          }, monthLabel));
        }));
      }));
    }
  }]);

  return MonthPanel;
}(Component);

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

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

export default MonthPanel;