import { familiarity_know_well, familiarity_master } from '@/page/subject/learnWord/word-table'
import dayjs from 'dayjs'

export const word_book_mode_print = '1'
export const word_book_mode_test = '2'

export function useUserWordBook() {
  // 熟悉度
  const graspOptions = ref([
    {
      value: '',
      label: '全部',
      originLabel: '全部',
      key: 'wordCount',
    },
    {
      value: '0',
      label: '未解锁',
      originLabel: '未解锁',
      key: 'wordUnlockCount',
    },
    {
      value: '1',
      label: '陌生',
      originLabel: '陌生',
      key: 'wordStrangerCount',
    },
    {
      value: '2',
      label: '认识',
      originLabel: '认识',
      key: 'wordKnowCount',
    },
    {
      value: familiarity_know_well,
      label: '熟悉',
      originLabel: '熟悉',
      key: 'wordKnowWellCount',
    },
    {
      value: familiarity_master,
      label: '掌握',
      originLabel: '掌握',
      key: 'wordGraspCount',
    },
  ])
  const grasp = ref('')

  const dateFmt = 'YYYY-MM-DD'
  const dateTimeFmt = 'YYYY-MM-DD HH:mm:ss'
  // 时间
  const time_all = ''
  const time_yesterday = '1'
  const time_today = '2'
  const time_3_day = '3'
  const time_7_day = '4'
  const time_1_month = '5'
  const timeOptions = ref([
    {
      value: time_all,
      label: '全部',
    },
    {
      value: time_yesterday,
      label: '昨天',
    },
    {
      value: time_today,
      label: '今天',
    },
    {
      value: time_3_day,
      label: '近3天',
    },
    {
      value: time_7_day,
      label: '近7天',
    },
    {
      value: time_1_month,
      label: '近1个月',
    },
  ])
  const time = ref(time_all)

  // 请求参数
  function getTimeParams() {
    let startTime: any
    let endTime: any
    if (time.value === time_all) {
      startTime = undefined
      endTime = undefined
    } else if (time.value === time_yesterday) {
      startTime = dayjs().subtract(1, 'day').format(dateFmt)
      endTime = dayjs().format(dateFmt)
    } else if (time.value === time_today) {
      startTime = dayjs().format(dateFmt)
      endTime = dayjs().format(dateTimeFmt)
    } else if (time.value === time_3_day) {
      startTime = dayjs().subtract(3, 'day').format(dateFmt)
      endTime = dayjs().format(dateTimeFmt)
    } else if (time.value === time_7_day) {
      startTime = dayjs().subtract(7, 'day').format(dateFmt)
      endTime = dayjs().format(dateTimeFmt)
    } else if (time.value === time_1_month) {
      startTime = dayjs().subtract(1, 'month').format(dateFmt)
      endTime = dayjs().format(dateTimeFmt)
    }
    if (startTime && !startTime.includes(':')) {
      startTime += ' 00:00:00'
    }
    if (endTime && !endTime.includes(':')) {
      endTime += ' 00:00:00'
    }
    return {
      startTime,
      endTime,
    }
  }

  return {
    time,
    timeOptions,
    grasp,
    graspOptions,
    getTimeParams,
  }
}
