"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

var _util = require("../util");

var CalendarHeader = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(CalendarHeader, _Component);

  var _super = (0, _createSuper2["default"])(CalendarHeader);

  function CalendarHeader() {
    (0, _classCallCheck2["default"])(this, CalendarHeader);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(CalendarHeader, [{
    key: "onYearChange",
    value: function onYearChange(year) {
      var newValue = this.props.value.clone();
      newValue.year(parseInt(year, 10));
      this.props.onValueChange(newValue);
    }
  }, {
    key: "onMonthChange",
    value: function onMonthChange(month) {
      var newValue = this.props.value.clone();
      newValue.month(parseInt(month, 10));
      this.props.onValueChange(newValue);
    }
  }, {
    key: "yearSelectElement",
    value: function yearSelectElement(year) {
      var _this$props = this.props,
          yearSelectOffset = _this$props.yearSelectOffset,
          yearSelectTotal = _this$props.yearSelectTotal,
          prefixCls = _this$props.prefixCls,
          Select = _this$props.Select;
      var start = year - yearSelectOffset;
      var end = start + yearSelectTotal;
      var options = [];

      for (var index = start; index < end; index++) {
        options.push( /*#__PURE__*/_react["default"].createElement(Select.Option, {
          key: "".concat(index)
        }, index));
      }

      return /*#__PURE__*/_react["default"].createElement(Select, {
        className: "".concat(prefixCls, "-header-year-select"),
        onChange: this.onYearChange.bind(this),
        dropdownStyle: {
          zIndex: 2000
        },
        dropdownMenuStyle: {
          maxHeight: 250,
          overflow: 'auto',
          fontSize: 12
        },
        optionLabelProp: "children",
        value: String(year),
        showSearch: false
      }, options);
    }
  }, {
    key: "monthSelectElement",
    value: function monthSelectElement(month) {
      var props = this.props;
      var t = props.value.clone();
      var prefixCls = props.prefixCls;
      var options = [];
      var Select = props.Select;

      for (var index = 0; index < 12; index++) {
        t.month(index);
        options.push( /*#__PURE__*/_react["default"].createElement(Select.Option, {
          key: "".concat(index)
        }, (0, _util.getMonthName)(t)));
      }

      return /*#__PURE__*/_react["default"].createElement(Select, {
        className: "".concat(prefixCls, "-header-month-select"),
        dropdownStyle: {
          zIndex: 2000
        },
        dropdownMenuStyle: {
          maxHeight: 250,
          overflow: 'auto',
          overflowX: 'hidden',
          fontSize: 12
        },
        optionLabelProp: "children",
        value: String(month),
        showSearch: false,
        onChange: this.onMonthChange.bind(this)
      }, options);
    }
  }, {
    key: "changeTypeToDate",
    value: function changeTypeToDate() {
      this.props.onTypeChange('date');
    }
  }, {
    key: "changeTypeToMonth",
    value: function changeTypeToMonth() {
      this.props.onTypeChange('month');
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          value = _this$props2.value,
          locale = _this$props2.locale,
          prefixCls = _this$props2.prefixCls,
          type = _this$props2.type,
          showTypeSwitch = _this$props2.showTypeSwitch,
          headerComponents = _this$props2.headerComponents;
      var year = value.year();
      var month = value.month();
      var yearSelect = this.yearSelectElement(year);
      var monthSelect = type === 'month' ? null : this.monthSelectElement(month);
      var switchCls = "".concat(prefixCls, "-header-switcher");
      var typeSwitcher = showTypeSwitch ? /*#__PURE__*/_react["default"].createElement("span", {
        className: switchCls
      }, type === 'date' ? /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(switchCls, "-focus")
      }, locale.month) : /*#__PURE__*/_react["default"].createElement("span", {
        onClick: this.changeTypeToDate.bind(this),
        className: "".concat(switchCls, "-normal")
      }, locale.month), type === 'month' ? /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(switchCls, "-focus")
      }, locale.year) : /*#__PURE__*/_react["default"].createElement("span", {
        onClick: this.changeTypeToMonth.bind(this),
        className: "".concat(switchCls, "-normal")
      }, locale.year)) : null;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-header")
      }, typeSwitcher, monthSelect, yearSelect, headerComponents);
    }
  }]);
  return CalendarHeader;
}(_react.Component);

exports["default"] = CalendarHeader;
(0, _defineProperty2["default"])(CalendarHeader, "defaultProps", {
  yearSelectOffset: 10,
  yearSelectTotal: 20,
  onValueChange: _noop["default"],
  onTypeChange: _noop["default"]
});
//# sourceMappingURL=CalendarHeader.js.map
