"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setPickerDateBySettingType = exports.isCurrentDateInRanges = exports.getPreviousValues = exports.getPickerDateBySettingType = exports.getNextValues = exports.getDaysOfMonth = exports.getCurrentWeekDay = exports.getCurrentValues = exports.YEAR_DECADE_COUNT = exports.WEEK_DAYS_COUNT = exports.SHORTCUTS = exports.RangeWeekPickerShortcutsKeysMapping = exports.RangeSettingTypes = exports.RangePickerShortcutsKeysMapping = exports.PickerTriggerClass = exports.PickerRangesClass = exports.PickerRangeTriggerClass = exports.PickerPanelClass = exports.PickerMinDate = exports.PickerMaxDate = exports.PickerHeadClass = exports.PickerFormat = exports.PickerDropdownClass = exports.PickerClass = exports.PickerCellClass = exports.PickerBodyClass = exports.MONTHDATAMAPEN = exports.MONTHDATAMAP = void 0;

var _cloneDeep = _interopRequireDefault(require("clone-deep"));

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

var _getLocale = require("../../utils/getLocale");

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

var PickerClass = 'tita-ui__picker';
exports.PickerClass = PickerClass;
var PickerHeadClass = 'tita-ui__picker-head';
exports.PickerHeadClass = PickerHeadClass;
var PickerBodyClass = 'tita-ui__picker-body';
exports.PickerBodyClass = PickerBodyClass;
var PickerPanelClass = 'tita-ui__picker-panel';
exports.PickerPanelClass = PickerPanelClass;
var PickerCellClass = 'tita-ui__picker-cell';
exports.PickerCellClass = PickerCellClass;
var PickerTriggerClass = 'tita-ui__picker-trigger';
exports.PickerTriggerClass = PickerTriggerClass;
var PickerDropdownClass = 'tita-ui__picker-dropdown';
exports.PickerDropdownClass = PickerDropdownClass;
var PickerRangesClass = 'tita-ui__picker-ranges';
exports.PickerRangesClass = PickerRangesClass;
var PickerRangeTriggerClass = 'tita-ui__picker-ranges-trigger';
exports.PickerRangeTriggerClass = PickerRangeTriggerClass;
var MONTHDATAMAP = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
exports.MONTHDATAMAP = MONTHDATAMAP;
var MONTHDATAMAPEN = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
exports.MONTHDATAMAPEN = MONTHDATAMAPEN;
var WEEK_DAYS_COUNT = 7;
exports.WEEK_DAYS_COUNT = WEEK_DAYS_COUNT;
var YEAR_DECADE_COUNT = 10;
exports.YEAR_DECADE_COUNT = YEAR_DECADE_COUNT;
var PickerFormat = 'YYYY/MM/DD';
exports.PickerFormat = PickerFormat;
var PickerMaxDate = (0, _moment["default"])().set({
  year: (0, _moment["default"])().year() + YEAR_DECADE_COUNT,
  month: 11,
  date: 31
}).format(PickerFormat);
exports.PickerMaxDate = PickerMaxDate;
var PickerMinDate = '2018/01/01';
exports.PickerMinDate = PickerMinDate;
var SHORTCUTS;
exports.SHORTCUTS = SHORTCUTS;

(function (SHORTCUTS) {
  SHORTCUTS["CURRENT_YEAR"] = "currentYear";
  SHORTCUTS["CURRENT_MONTH"] = "currentMonth";
  SHORTCUTS["CURRENT_WEEKDAY"] = "currentWeekDay";
  SHORTCUTS["CURRENT_WEEK"] = "currentWeek";
  SHORTCUTS["PREVIOUS_WEEK"] = "prevWeek";
  SHORTCUTS["NEXT_WEEK"] = "nextWeek";
  SHORTCUTS["TODAY"] = "today";
})(SHORTCUTS || (exports.SHORTCUTS = SHORTCUTS = {}));

var getCurrentValues = function getCurrentValues(symbol) {
  return [(0, _moment["default"])().startOf(symbol), (0, _moment["default"])().endOf(symbol)];
};

exports.getCurrentValues = getCurrentValues;

var getCurrentWeekDay = function getCurrentWeekDay() {
  return [(0, _moment["default"])().weekday(1), (0, _moment["default"])().weekday(7)];
};

exports.getCurrentWeekDay = getCurrentWeekDay;

var getPreviousValues = function getPreviousValues(symbol) {
  return [(0, _moment["default"])().subtract(1, symbol).startOf(symbol), (0, _moment["default"])().subtract(1, symbol).endOf(symbol)];
};

exports.getPreviousValues = getPreviousValues;

var getNextValues = function getNextValues(symbol) {
  return [(0, _moment["default"])().add(1, symbol).startOf(symbol), (0, _moment["default"])().add(1, symbol).endOf(symbol)];
};

exports.getNextValues = getNextValues;
var RangeSettingTypes;
exports.RangeSettingTypes = RangeSettingTypes;

(function (RangeSettingTypes) {
  RangeSettingTypes["END"] = "endDate";
  RangeSettingTypes["RESET"] = "reset";
  RangeSettingTypes["START"] = "startDate";
})(RangeSettingTypes || (exports.RangeSettingTypes = RangeSettingTypes = {}));

var RangePickerShortcutsKeysMapping = function RangePickerShortcutsKeysMapping() {
  return [{
    key: SHORTCUTS.TODAY,
    title: (0, _getLocale.getLocale)('Mod_Today')
  }, {
    key: SHORTCUTS.CURRENT_WEEKDAY,
    title: (0, _getLocale.getLocale)('Feed_Tab_Title_Thisweek')
  }, {
    key: SHORTCUTS.CURRENT_MONTH,
    title: (0, _getLocale.getLocale)('Feed_Tab_Title_Thismonth')
  }, {
    key: SHORTCUTS.CURRENT_YEAR,
    title: (0, _getLocale.getLocale)('Feed_Tab_Title_Thisyear')
  }];
};

exports.RangePickerShortcutsKeysMapping = RangePickerShortcutsKeysMapping;

var RangeWeekPickerShortcutsKeysMapping = function RangeWeekPickerShortcutsKeysMapping() {
  return [{
    key: SHORTCUTS.PREVIOUS_WEEK,
    title: (0, _getLocale.getLocale)('Rep_NewS_LastWeek')
  }, {
    key: SHORTCUTS.CURRENT_WEEK,
    title: (0, _getLocale.getLocale)('Feed_Tab_Title_Thisweek')
  }, {
    key: SHORTCUTS.NEXT_WEEK,
    title: (0, _getLocale.getLocale)('Mod_NextWeek')
  }];
};

exports.RangeWeekPickerShortcutsKeysMapping = RangeWeekPickerShortcutsKeysMapping;

var getPickerDateBySettingType = function getPickerDateBySettingType(params) {
  var _params$defaultValue = params.defaultValue,
      defaultValue = _params$defaultValue === void 0 ? (0, _moment["default"])() : _params$defaultValue,
      _params$format = params.format,
      format = _params$format === void 0 ? PickerFormat : _params$format,
      settingType = params.settingType,
      values = params.values;

  if (values instanceof Array && settingType) {
    var valuesLen = values.length;
    var startDate = values[0] || (0, _moment["default"])().format(format);
    var endDate = values[valuesLen - 1] || (0, _moment["default"])().format(format);
    return settingType === RangeSettingTypes.START ? startDate : endDate;
  }

  return defaultValue;
};

exports.getPickerDateBySettingType = getPickerDateBySettingType;

var setPickerDateBySettingType = function setPickerDateBySettingType(params) {
  var newDate = params.newDate,
      settingType = params.settingType,
      values = params.values;

  if (values instanceof Array && settingType) {
    var valuesClone = (0, _cloneDeep["default"])(values);
    var isSettingStartDate = settingType === RangeSettingTypes.START;
    var isResetRangeDate = settingType === RangeSettingTypes.RESET;
    if (isResetRangeDate) return [(0, _moment["default"])(newDate)];
    var updateIndex = isSettingStartDate ? 0 : 1;
    valuesClone.splice(updateIndex, 1, (0, _moment["default"])(newDate));

    if (isSettingStartDate && (0, _moment["default"])(newDate, PickerFormat).isAfter((0, _moment["default"])(valuesClone[1]).format(PickerFormat), 'date')) {
      valuesClone[0] = valuesClone[1];
      valuesClone[1] = (0, _moment["default"])(newDate);
    }

    if (!isSettingStartDate && (0, _moment["default"])(newDate, PickerFormat).isBefore((0, _moment["default"])(valuesClone[0]).format(PickerFormat), 'date')) {
      valuesClone[1] = valuesClone[0];
      valuesClone[0] = (0, _moment["default"])(newDate);
    }

    return valuesClone.slice(0, 2);
  }

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

exports.setPickerDateBySettingType = setPickerDateBySettingType;

var isCurrentDateInRanges = function isCurrentDateInRanges(params) {
  var _params$format2 = params.format,
      format = _params$format2 === void 0 ? PickerFormat : _params$format2,
      nowDate = params.nowDate,
      values = params.values;
  var date = typeof nowDate === 'string' ? nowDate : nowDate.format(format);
  var data = {
    inRanges: false,
    rangeStart: false,
    rangeEnd: false
  };

  if (values instanceof Array) {
    var valuesLen = values.length;
    var startDate = values[0] || '';
    var endDate = values[valuesLen - 1] || '';
    if (!startDate || !endDate || valuesLen < 2) return data;

    if ((0, _moment["default"])(date).isBetween((0, _moment["default"])(startDate).format(format), (0, _moment["default"])(endDate).format(format), null, '[]')) {
      return {
        inRanges: true,
        rangeStart: (0, _moment["default"])(date).isSame((0, _moment["default"])(startDate).format(format)),
        rangeEnd: (0, _moment["default"])(date).isSame((0, _moment["default"])(endDate).format(format))
      };
    }

    return data;
  }

  return data;
}; //获取某年某月有多少天


exports.isCurrentDateInRanges = isCurrentDateInRanges;

var getDaysOfMonth = function getDaysOfMonth(year, month) {
  switch (month) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      return 31;

    case 4:
    case 6:
    case 9:
    case 11:
      return 30;

    case 2:
      return year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28;

    default:
      return 0;
  }
};

exports.getDaysOfMonth = getDaysOfMonth;