"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isDisabledDate = isDisabledDate;
exports.checkMomentObj = checkMomentObj;
exports.formatDateValue = formatDateValue;
exports.getVisibleMonth = getVisibleMonth;
exports.isSameYearMonth = isSameYearMonth;
exports.preFormatDateValue = preFormatDateValue;
exports.getLocaleData = getLocaleData;
exports.CALENDAR_MODES = exports.CALENDAR_MODE_DATE = exports.CALENDAR_MODE_MONTH = exports.CALENDAR_MODE_YEAR = exports.YEAR_TABLE_COL_COUNT = exports.YEAR_TABLE_ROW_COUNT = exports.MONTH_TABLE_COL_COUNT = exports.MONTH_TABLE_ROW_COUNT = exports.CALENDAR_TABLE_ROW_COUNT = exports.CALENDAR_TABLE_COL_COUNT = exports.DAYS_OF_WEEK = void 0;

var _moment = _interopRequireDefault(require("moment"));

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var DAYS_OF_WEEK = 7;
exports.DAYS_OF_WEEK = DAYS_OF_WEEK;
var CALENDAR_TABLE_COL_COUNT = 7;
exports.CALENDAR_TABLE_COL_COUNT = CALENDAR_TABLE_COL_COUNT;
var CALENDAR_TABLE_ROW_COUNT = 6;
exports.CALENDAR_TABLE_ROW_COUNT = CALENDAR_TABLE_ROW_COUNT;
var MONTH_TABLE_ROW_COUNT = 4;
exports.MONTH_TABLE_ROW_COUNT = MONTH_TABLE_ROW_COUNT;
var MONTH_TABLE_COL_COUNT = 3;
exports.MONTH_TABLE_COL_COUNT = MONTH_TABLE_COL_COUNT;
var YEAR_TABLE_ROW_COUNT = 4;
exports.YEAR_TABLE_ROW_COUNT = YEAR_TABLE_ROW_COUNT;
var YEAR_TABLE_COL_COUNT = 3;
exports.YEAR_TABLE_COL_COUNT = YEAR_TABLE_COL_COUNT;
var CALENDAR_MODE_YEAR = 'year';
exports.CALENDAR_MODE_YEAR = CALENDAR_MODE_YEAR;
var CALENDAR_MODE_MONTH = 'month';
exports.CALENDAR_MODE_MONTH = CALENDAR_MODE_MONTH;
var CALENDAR_MODE_DATE = 'date';
exports.CALENDAR_MODE_DATE = CALENDAR_MODE_DATE;
var CALENDAR_MODES = [CALENDAR_MODE_DATE, CALENDAR_MODE_MONTH, CALENDAR_MODE_YEAR];
exports.CALENDAR_MODES = CALENDAR_MODES;

function isDisabledDate(date, fn, view) {
  if (typeof fn === 'function' && fn(date, view)) {
    return true;
  }

  return false;
}

function checkMomentObj(props, propName, componentName) {
  if (props[propName] && !_moment["default"].isMoment(props[propName])) {
    return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Required a moment object"));
  }
}

function formatDateValue(value) {
  var reservedValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;

  if (value && _moment["default"].isMoment(value)) {
    return value;
  }

  return reservedValue;
}

function getVisibleMonth(defaultVisibleMonth, value) {
  var getVM = defaultVisibleMonth;

  if (typeof getVM !== 'function' || !_moment["default"].isMoment(getVM())) {
    getVM = function getVM() {
      if (value) {
        return value;
      }

      return (0, _moment["default"])();
    };
  }

  return getVM();
}

function isSameYearMonth(dateA, dateB) {
  return dateA.month() === dateB.month() && dateA.year() === dateB.year();
}

function preFormatDateValue(value, format) {
  var val = typeof value === 'string' ? (0, _moment["default"])(value, format, false) : value;

  if (val && _moment["default"].isMoment(val) && val.isValid()) {
    return val;
  }

  return null;
}

function getLocaleData(_ref, localeData) {
  var _months = _ref.months,
      shortMonths = _ref.shortMonths,
      _firstDayOfWeek = _ref.firstDayOfWeek,
      _weekdays = _ref.weekdays,
      shortWeekdays = _ref.shortWeekdays,
      veryShortWeekdays = _ref.veryShortWeekdays;
  return _objectSpread({}, localeData, {
    monthsShort: function monthsShort() {
      return shortMonths || localeData.monthsShort();
    },
    months: function months() {
      return _months || localeData.months();
    },
    firstDayOfWeek: function firstDayOfWeek() {
      return _firstDayOfWeek || localeData.firstDayOfWeek();
    },
    weekdays: function weekdays() {
      return _weekdays || localeData.weekdays;
    },
    weekdaysShort: function weekdaysShort() {
      return shortWeekdays || localeData.weekdaysShort();
    },
    weekdaysMin: function weekdaysMin() {
      return veryShortWeekdays || localeData.weekdaysMin();
    }
  });
}