<template>
  <component :is="currentCompoent" :chapter="chapter" :data="data" v-bind="$attrs" v-on="$listeners" v-if="chapter" />
</template>

<script>
// componets
import ChapterWork from './chapterWork.vue'
import ChapterTest from './chapterTest.vue'

export default {
  name: 'ViewerWork',
  components: { ChapterWork, ChapterTest },
  props: {
    // 当前选中的
    chapter: {
      type: Object,
      default() {
        return {}
      }
    },
    // 课程详情接口返回的数据
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    currentCompoent() {
      const componentNames = {
        1: 'ChapterTest', // 课后测验
        2: 'ChapterWork' // 作业
      }
      const homework = this.chapter.homework
      return homework ? componentNames[homework.work_type] : ''
    }
  }
}
</script>
