export const state = () => ({
  items: [],
  item: {}
})

export const actions = {
  async fetchCourses({commit}) {
    console.log('store/course.js actions > fetchCourses')
    const courses = await this.$axios.$get('/api/v1/products')
    console.log('store/course.js actions > fetchCourses > await this.$axios.$get')
    commit('setItems', {resource: 'course', items: courses}, {root: true})
    console.log('store/course.js actions > fetchCourses > await this.$axios.$get > commit')
    return state.items
  },
  async fetchCourseBySlug({commit, state}, courseSlug) {
    const course = await this.$axios.$get(`/api/v1/products/s/${courseSlug}`)
    if(course.isAxiosError === true){
      console.log(course.data)
      return Error('')
    }
    commit('setCourse', course)
    return state.course
  }
}

export const mutations = {
  setCourse(state, course) {
    state.item = course
  }
}