import { ref, computed, watch } from 'vue'
import useFetch from './useFetch'
import { getTodayByDay } from '@/utils/common'

const useDayOptions = (dataModel: any, notIncludeCurDay?: any) => {
  const dayList = ref([])
  const today = getTodayByDay()
  function fetchDayList() {
    if (dataModel.subject && dataModel.question) {
      useFetch('getDayList')
        .fetch({ subjectCode: dataModel.subject, questionMainNumber: dataModel.question })
        .then((res: any) => {
          dayList.value = res
            .filter((item: any) => item.key != today)
            .map((item: any) => ({ label: item.value, value: item.key }))
        })
    }
  }
  watch([() => dataModel.subject, () => dataModel.question], (a: any, b: any) => {
    fetchDayList()
  })
  fetchDayList()

  const dayOptions = computed<any>(() =>
    [
      { label: '当天', value: today },
      { label: '全部', value: '' },
      notIncludeCurDay ? { label: '全部(不含当天)', value: 'notIncludeCurDay' } : null,
      ...dayList.value,
    ].filter((v) => !!v)
  )
  return {
    dayOptions,
  }
}
export default useDayOptions
