<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 ChapterExam from './chapterExam.vue'

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