"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

var _createReactClass = _interopRequireDefault(require("create-react-class"));

var _noop = _interopRequireDefault(require("lodash/noop"));

var _MonthTable = _interopRequireDefault(require("./MonthTable"));

function goYear(direction) {
  var next = this.state.value.clone();
  next.add(direction, 'year');
  this.setAndChangeValue(next);
}

var MonthPanel = (0, _createReactClass["default"])({
  displayName: "MonthPanel",
  getDefaultProps: function getDefaultProps() {
    return {
      onChange: _noop["default"],
      onSelect: _noop["default"]
    };
  },
  getInitialState: function getInitialState() {
    var props = this.props; // bind methods

    this.nextYear = goYear.bind(this, 1);
    this.previousYear = goYear.bind(this, -1);
    this.prefixCls = "".concat(props.rootPrefixCls, "-month-panel");
    return {
      value: props.value || props.defaultValue
    };
  },
  componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
    if ('value' in nextProps) {
      this.setState({
        value: nextProps.value
      });
    }
  },
  setAndChangeValue: function setAndChangeValue(value) {
    this.setValue(value);
    this.props.onChange(value);
  },
  setAndSelectValue: function setAndSelectValue(value) {
    this.setValue(value);
    this.props.onSelect(value);
  },
  setValue: function setValue(value) {
    if (!('value' in this.props)) {
      this.setState({
        value: value
      });
    }
  },
  render: function render() {
    var props = this.props;
    var value = this.state.value;
    var cellRender = props.cellRender;
    var contentRender = props.contentRender;
    var locale = props.locale;
    var year = value.year();
    var prefixCls = this.prefixCls;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: prefixCls,
      style: props.style
    }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, "-header")
    }, /*#__PURE__*/_react["default"].createElement("a", {
      className: "".concat(prefixCls, "-prev-year-btn"),
      role: "button",
      onClick: this.previousYear,
      title: locale.previousYear
    }), /*#__PURE__*/_react["default"].createElement("a", {
      className: "".concat(prefixCls, "-year-select"),
      role: "button",
      onClick: props.onYearPanelShow,
      title: locale.yearSelect
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "-year-select-content")
    }, year), /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "-year-select-arrow")
    }, "x")), /*#__PURE__*/_react["default"].createElement("a", {
      className: "".concat(prefixCls, "-next-year-btn"),
      role: "button",
      onClick: this.nextYear,
      title: locale.nextYear
    })), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, "-body")
    }, /*#__PURE__*/_react["default"].createElement(_MonthTable["default"], {
      disabledDate: props.disabledDate,
      onSelect: this.setAndSelectValue,
      locale: locale,
      value: value,
      cellRender: cellRender,
      contentRender: contentRender,
      prefixCls: prefixCls
    }))));
  }
});
var _default = MonthPanel;
exports["default"] = _default;
//# sourceMappingURL=MonthPanel.js.map
