import { getExperimentList } from '../api'

export interface ExperimentType {
  id: string
  name: string
}

export function useGetExperimentList() {
  const experiments = ref<ExperimentType[]>([])
  function updateExperiments(courseId?: string) {
    if (!courseId) {
      experiments.value = []
      return
    }
    getExperimentList({ course_id: courseId }).then((res: any) => {
      experiments.value = res.data
    }).catch((err) => {
      console.error('获取实验列表失败', err)
      experiments.value = []
    })
  }
  return { experiments, updateExperiments }
}
