import { defineStore } from 'pinia'
import { subjects } from '@/api/subject/config'

export const subjectStore = defineStore('subject', () => {
  // 学科
  const subjectObj = {
    id: '',
    name: '',
  }
  const subject = reactive(subjectObj)

  // 切换学科
  const selectSubject = (item: anyObj) => {
    subject.id = item.id
    subject.name = item.name
  }

  // 难度系数（容易/较易/一般/较难/困难）
  const difficulty = ref<string>('')

  const subjectList = ref<any[]>([])
  const getSubjectAllList = async () => {
    subjectList.value = subjects
  }

  const $reset = () => {
    Object.assign(subject, subjectObj)
    difficulty.value = ''
    subjectList.value = []
  }

  return {
    subject,
    selectSubject,
    difficulty,
    subjectList,
    getSubjectAllList,
    $reset,
  }
})

// 自由组卷练习参数
export const groupPaperStore = defineStore('groupPape', () => {
  const groupPaperParams = ref<{
    subjectId: string
    paperScore?: anyObj[]
    trainType: number // 练习类型（1-章节 2-知识点）
    id?: any
  }>()

  const $reset = () => {
    groupPaperParams.value = undefined
  }

  return {
    groupPaperParams,
    $reset,
  }
})
