"use strict";

exports.__esModule = true;
exports.range = range;
exports.rangeMonthOptions = rangeMonthOptions;
exports.rangeOptions = rangeOptions;
exports.resetMonth = resetMonth;
exports.resetTime = resetTime;

var _dayjs = _interopRequireDefault(require("dayjs"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function range(min, max) {
  var result = [];

  for (var i = min; i <= max; i++) {
    result.push(i);
  }

  return result;
}

function rangeOptions(min, max, suffix) {
  return range(min, max).map(function (it) {
    return {
      label: "" + it + (suffix || ''),
      value: it
    };
  });
}

function rangeMonthOptions(start, end, suffix) {
  start = (0, _dayjs.default)(start);
  end = (0, _dayjs.default)(end);
  var endOfMonth = end.endOf('month');
  var startOfMonth = start.startOf('month');
  var ret = rangeOptions(1, 12, suffix);

  if (!end.subtract(1, 'year').isAfter(start)) {
    ret = [];

    do {
      var m = +(0, _dayjs.default)(startOfMonth).format('M');
      ret.push({
        label: "" + m + (suffix || ''),
        value: m
      });
      startOfMonth = (0, _dayjs.default)(startOfMonth).add(1, 'month');
    } while (startOfMonth.isBefore(endOfMonth) && ret.length < 12);
  }

  return ret;
}

function resetMonth(d) {
  d.setDate(1);
  d.setMonth(0);
}

function resetTime(d) {
  d.setHours(0);
  d.setMinutes(0);
  d.setSeconds(0);
  d.setMilliseconds(0);
}