import dayjs from "dayjs";

const generateShortcuts = (t) => {
  return [
      {
        text: t('common.yesterday'),
        value: () => {
          return yesterday()
        },
      },
      {
        text: t('common.today'),
        value: () => {
          return today()
        },
      },
      {
        text: t('common.recentWeek'),
        value: () => {
          return recentWeek()
        },
      },
      {
        text: t('common.recentMonth'),
        value: () => {
            return recentMonth()
        }
      },
      {
        text: t('common.lastMonth'),
        value: () => {
          return lastMonth()
        },
      },
      {
        text: t('common.currentMonth'),
        value: () => {
          return currentMonth()
        },
      },
      {
        text: t('common.recent3Month'),
        value: () => {
          return recent3Month()
        },
      }
  ];
}

const yesterday = () => {
  const yesterday = dayjs().subtract(1, 'day');
  return [yesterday.startOf('day').format("YYYY-MM-DD"), yesterday.endOf('day').format("YYYY-MM-DD")];
}

const today = () => {
  const today = dayjs();
  return [today.startOf('day').format("YYYY-MM-DD"), today.endOf('day').format("YYYY-MM-DD")];
}

const recentWeek = () => {
  const start = dayjs().subtract(6, 'day').startOf('day');
  const end = dayjs().endOf('day');
  return [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
}

const recentMonth = () => {
  const today = dayjs();
  const start = today.subtract(29, 'day').startOf('day');
  const end = today.endOf('day');
  return [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
}

const lastMonth = () => {
  const start = dayjs().subtract(1, 'month').startOf('month');
  const end = dayjs().subtract(1, 'month').endOf('month');
  return [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
}

const currentMonth = () => {
  const start = dayjs().startOf('month');
  const end = dayjs().endOf('month');
  return [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
}

const recent3Month = () => {
  const end = dayjs(); // 当前日期  
  const start = dayjs().subtract(3, 'month');
  return [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
}

export { generateShortcuts, recent3Month, yesterday, today, recentWeek, recentMonth, lastMonth, currentMonth }