'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getWeekDays = exports.isDayInMonth = exports.compareDates = exports.getArrayOfWeeks = undefined;

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

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

var _getCalendarStart = function _getCalendarStart(referenceDate) {
  return referenceDate.clone().startOf('month').startOf('week');
};

var getArrayOfWeeks = function getArrayOfWeeks(referenceDate) {
  var weeks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;

  var weeksList = new Array(weeks);
  var day = _getCalendarStart(referenceDate).clone();
  for (var i = 0; i < weeksList.length; i++) {
    weeksList[i] = [];
    for (var j = 0; j < 7; j++) {
      weeksList[i][j] = day.clone();
      day.add(1, 'd');
    }
  }
  return weeksList;
};

/** Compare two `moment`'s by date. */
var compareDates = function compareDates(oneDate, otherDate) {
  return oneDate.year() === otherDate.year() && oneDate.month() === otherDate.month() && oneDate.date() === otherDate.date();
};

/** Check if given day is in the `date`'s month. */
var isDayInMonth = function isDayInMonth(day, date) {
  var currentMonth = date.month();
  return day.month() === currentMonth;
};

/** Return array of week day names.
 * 
 * getWeekDays() --> ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Su']
 */
var getWeekDays = function getWeekDays() {
  var long = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

  var weekDays = [];
  var day = (0, _moment2.default)().startOf('week');
  for (var i = 0; i < 7; i++) {
    weekDays[i] = day.format(long ? 'dddd' : 'dd');
    day.add(1, 'd');
  }
  return weekDays;
};

exports.getArrayOfWeeks = getArrayOfWeeks;
exports.compareDates = compareDates;
exports.isDayInMonth = isDayInMonth;
exports.getWeekDays = getWeekDays;