import { DateUtils } from '../utils';
export var setTimingMargin = function setTimingMargin(date, way) {
  if (way === void 0) {
    way = 'left';
  }

  return way === 'right' ? DateUtils.endOfDay(date) : DateUtils.startOfDay(date);
};
export function getCalendarDate(_ref) {
  var _value;

  var value = _ref.value;
  // Update calendarDate if the value is not null
  value = (_value = value) !== null && _value !== void 0 ? _value : [];

  if (value[0] && value[1]) {
    var sameMonth = DateUtils.isSameMonth(value[0], value[1]);
    return [value[0], sameMonth ? DateUtils.addMonths(value[1], 1) : value[1]]; // If only the start date
  } else if (value[0]) {
    return [value[0], DateUtils.addMonths(value[0], 1)];
  }

  var todayDate = new Date();
  return [todayDate, DateUtils.addMonths(todayDate, 1)];
}
export var getDefaultRanges = function getDefaultRanges() {
  var todayDate = new Date();
  return [{
    label: 'today',
    value: [setTimingMargin(todayDate), setTimingMargin(todayDate, 'right')]
  }, {
    label: 'yesterday',
    value: [setTimingMargin(DateUtils.addDays(todayDate, -1)), setTimingMargin(DateUtils.addDays(todayDate, -1), 'right')]
  }, {
    label: 'last7Days',
    value: [setTimingMargin(DateUtils.subDays(todayDate, 6)), setTimingMargin(todayDate, 'right')]
  }];
};
export var isSameValueType = function isSameValueType(source, dest) {
  var _source$, _dest$, _source$2, _dest$2;

  return (source === null || source === void 0 ? void 0 : (_source$ = source[0]) === null || _source$ === void 0 ? void 0 : _source$.valueOf()) === (dest === null || dest === void 0 ? void 0 : (_dest$ = dest[0]) === null || _dest$ === void 0 ? void 0 : _dest$.valueOf()) && (source === null || source === void 0 ? void 0 : (_source$2 = source[1]) === null || _source$2 === void 0 ? void 0 : _source$2.valueOf()) === (dest === null || dest === void 0 ? void 0 : (_dest$2 = dest[1]) === null || _dest$2 === void 0 ? void 0 : _dest$2.valueOf());
};
export var getMonthHoverRange = function getMonthHoverRange(date) {
  return [DateUtils.startOfMonth(date), DateUtils.endOfMonth(date)];
};
export var getWeekHoverRange = function getWeekHoverRange(isoWeek, date) {
  if (isoWeek) {
    // set to the first day of this week according to ISO 8601, 12:00 am
    return [DateUtils.startOfISOWeek(date), DateUtils.endOfISOWeek(date)];
  }

  return [DateUtils.startOfWeek(date), DateUtils.endOfWeek(date)];
};