import { FormSchema } from '@/components/Form'

export const searchTime: FormSchema = {
  field: 'time',
  label: '时间范围',
  component: 'DatePicker',
  value: '',
  componentProps: {
    type: 'datetimerange',
    valueFormat: 'YYYY/MM/DD HH:mm:ss',
    rangeSeparator: '至',
    shortcuts: [
      {
        text: '今天',
        value: () => {
          const end = new Date()
          const start = new Date()
          start.setDate(start.getDate())
          setDayTimeStart(start)
          return [start, end]
        }
      },
      {
        text: '昨天',
        value: () => {
          const end = new Date()
          const start = new Date()
          setDayTimeStart(end)
          start.setDate(start.getDate() - 1)
          setDayTimeStart(start)
          return [start, end]
        }
      },
      {
        text: '最近七天',
        value: () => {
          const end = new Date()
          const start = new Date()
          start.setDate(start.getDate() - 7)
          setDayTimeStart(start)
          setDayTimeStart(end)
          return [start, end]
        }
      },
      {
        text: '本月',
        value: () => {
          const end = new Date()
          const start = new Date()
          start.setMonth(start.getMonth() - 1)
          setDayTimeStart(start)
          return [start, end]
        }
      },
      {
        text: '上月',
        value: () => {
          const end = new Date()
          const start = new Date()
          start.setMonth(start.getMonth() - 3)
          setDayTimeStart(start)
          end.setMonth(end.getMonth() - 2)
          setDayTimeStart(end)
          return [start, end]
        }
      },
      {
        text: '本年',
        value: () => {
          const end = new Date()
          const start = new Date()
          start.setFullYear(start.getFullYear())
          start.setMonth(0)
          start.setDate(0)
          setDayTimeStart(start)
          return [start, end]
        }
      }
    ],
    placeholder: '请输入链接搜索'
  }
}

/**
 * 将给定的时间对象设置为当天的开始时间（即00:00:00）
 * 此函数的目的是标准化时间对象，使其代表一天的开始
 * @param time 一个代表时间的Date对象通过引用传递，函数将直接修改这个对象
 */
function setDayTimeStart(time: any) {
  time.setHours(0)
  time.setMinutes(0)
  time.setSeconds(0)
}
// function setMonthTimeEnd(time: any) {
//   time.setHours(0)
//   time.setMinutes(0)
//   time.setSeconds(0)
// }
// function getLastDayOfMonth(currentDate) {
//   // 2. 计算当前月份的下一个月的第一天
//   const nextMonthFirstDay = new Date(currentDate)
//   nextMonthFirstDay.setMonth(currentDate.getMonth() + 1, 1)

//   // 3. 将下一个月的第一天日期减去一天，得到当前月份的最后一天
//   const lastDayOfMonth = new Date(nextMonthFirstDay)
//   lastDayOfMonth.setDate(lastDayOfMonth.getDate() - 1)
//   return lastDayOfMonth
// }
