/**
 * Auth: 周群营
 * Date: Mar 27 2018
 * Desc: Plugin configs
 */

/**
 * @desc date range options
 * @return {object}
 */
export const dateRangeShortcutOptions = () => {
  const date = new Date();
  const getStartOfDay = day => Math.floor(day.setHours(0) / 3600000) * 3600000;
  const getEndOfDay = day => Math.ceil(day.setHours(23) / 3600000) * 3600000 - 24 * 3600000 - 1;
  const dayStartRange = day => getStartOfDay(new Date(date.getTime() - 3600000 * 24 * day));

  return {
    shortcuts: [{
      text: '今天',
      onClick(picker) {
        picker.$emit('pick', [getStartOfDay(date), Math.ceil(date.setHours(23) / 3600000) * 3600000 - 1]);
      }
    }, {
      text: '昨天',
      onClick(picker) {
        picker.$emit('pick', [dayStartRange(1), getEndOfDay(date)]);
      }
    }, {
      text: '过去7天',
      onClick(picker) {
        picker.$emit('pick', [dayStartRange(7), getEndOfDay(date)]);
      }
    }, {
      text: '过去14天',
      onClick(picker) {
        picker.$emit('pick', [dayStartRange(14), getEndOfDay(date)]);
      }
    }, {
      text: '过去30天',
      onClick(picker) {
        picker.$emit('pick', [dayStartRange(30), getEndOfDay(date)]);
      }
    }]
  };
};
