import axios from './config'

export const API_URL = 'https://pbl.cocorobo.cn/api/pbl/'

/**
 * 获取课程详情
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export const getCourseDetail = (courseId: string): Promise<any> => {
  return axios.get(`${API_URL}selectCourseDetail3`, {
    params: { courseId },
  })
}

/**
 * 提交作业接口
 * @param params 参数对象
 * @returns Promise<any>
 */
export interface SubmitWorkParams {
  uid: string
  cid: string
  stage: string
  task: string
  tool: string
  atool: string
  content: string
  type: string
}

export const submitWork = (params: SubmitWorkParams): Promise<any> => {
  return axios.post(`${API_URL}addCourseWorks_workPage`, [params])
}

/**
 * 查看作业接口
 * @param cid 课程ID
 * @param s s参数，传0
 * @param t 第几页幻灯片
 * @returns Promise<any>
 */
export const selectSWorks = (cid: string, s: string, t: string): Promise<any> => {
  return axios.get(`${API_URL}selectSWorks`, {
    params: {
      cid,
      s,
      t,
    },
  })
}

export const getHTML = (url: string): Promise<any> => {
  return axios.get(`${url}`)
}


export default {
  getCourseDetail,
  submitWork,
  selectSWorks,
  getHTML,
}
