"use strict";

exports.__esModule = true;
exports.default = void 0;
var _dayjs = _interopRequireDefault(require("dayjs"));
var _yearPicker = _interopRequireDefault(require("./year-picker"));
var _utils = require("../utils");
var _utils2 = require("../../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var MonthPicker = /*#__PURE__*/function (_YearPicker) {
  _inheritsLoose(MonthPicker, _YearPicker);
  function MonthPicker() {
    return _YearPicker.apply(this, arguments) || this;
  }
  var _proto = MonthPicker.prototype;
  _proto.getStep = function getStep() {
    return 'month';
  };
  _proto.getDisableType = function getDisableType() {
    return 'month';
  };
  _proto.getRangeCheck = function getRangeCheck() {
    return {
      date: {
        hasYear: true,
        hasMonth: true,
        hasDay: false
      }
    };
  };
  _proto.getDataSource = function getDataSource(locale) {
    var _this = this;
    var result = _YearPicker.prototype.getDataSource.call(this, locale);
    var monthLocale = (0, _utils2.get)(locale, 'locale.DatePicker.month', '月');
    var year = (0, _dayjs.default)().year(this.value.getFullYear());
    var startOfYear = year.startOf('year');
    var endOfYear = year.endOf('year');
    var range = this.validRange || [];
    var start = (0, _dayjs.default)(range[0] || '-');
    var end = (0, _dayjs.default)(range[1] || '-');
    var rangeOpts = (0, _utils.rangeOptions)(1, 12, monthLocale);
    if (startOfYear.isValid() && start.isValid() && end.isValid()) {
      if (start.isBefore(startOfYear) && end.isAfter(startOfYear) && end.isBefore(endOfYear)) {
        rangeOpts = (0, _utils.rangeMonthOptions)(startOfYear, end, monthLocale);
      } else if (start.isAfter(startOfYear) && end.isBefore(endOfYear)) {
        rangeOpts = (0, _utils.rangeMonthOptions)(start, end, monthLocale);
      } else if (start.isAfter(startOfYear) && start.isBefore(endOfYear) && end.isAfter(endOfYear)) {
        rangeOpts = (0, _utils.rangeMonthOptions)(start, endOfYear, monthLocale);
      }
    }
    result.push(this.filterDataSource(rangeOpts, function (d, it) {
      (0, _utils.resetTime)(d);
      d.setDate(1);
      d.setFullYear(_this.value.getFullYear());
      d.setMonth(it.value - 1);
    }, 'month'));
    return result;
  };
  _proto.toDate = function toDate(values) {
    var d = _YearPicker.prototype.toDate.call(this, values);
    d.setMonth(values[1] - 1);
    return d;
  };
  _proto.toValues = function toValues(d) {
    var values = _YearPicker.prototype.toValues.call(this, d);
    values.push(d.getMonth() + 1);
    return values;
  };
  return MonthPicker;
}(_yearPicker.default);
exports.default = MonthPicker;