import { ref, computed, watch } from 'vue'
import useFetch from './useFetch'
import useMainStore from '@/store/main'

const useDayOptions = (dataModel: any) => {
  const mainStore = useMainStore()
  const dayList = ref([])
  function fetchDayList() {
    if (dataModel.subject && dataModel.question) {
      useFetch('getDayListInGroup')
        // .fetch({ subjectCode: dataModel.subject, questionMainNumber: dataModel.question })
        .fetch({ examId: mainStore.myUserInfo?.examId })
        .then((res: any) => {
          dayList.value = res.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: '' }, ...dayList.value].filter((v) => !!v))
  return {
    dayOptions,
  }
}
export default useDayOptions
