import { ref, reactive, computed } from 'vue'
import { message } from 'ant-design-vue'
import { examAPI } from '../../../api/exam.js'

export function useTraining() {
  const trainTab = ref('checkpoint')
  const checkpointData = ref(null)
  const dailyQuestions = ref([])
  const loading = ref(false)
  
  const trainStats = computed(() => [
    { value: '3', label: '连续天数' },
    { value: '28', label: '已完成题数' },
    { value: '85%', label: '正确率' }
  ])

  const loadCheckpointData = async () => {
    loading.value = true
    try {
      const response = await examAPI.getCheckpoint()
      if (response.success) {
        checkpointData.value = response.data
      }
    } catch (error) {
      console.error('加载闯关数据失败:', error)
    } finally {
      loading.value = false
    }
  }

  const loadDailyQuestions = async () => {
    loading.value = true
    try {
      const response = await examAPI.getDailyQuestions()
      if (response.success) {
        dailyQuestions.value = response.data || []
      }
    } catch (error) {
      console.error('加载每日一练失败:', error)
    } finally {
      loading.value = false
    }
  }

  return {
    trainTab,
    checkpointData,
    dailyQuestions,
    loading,
    trainStats,
    loadCheckpointData,
    loadDailyQuestions
  }
}
