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

<script>
import CourseWork from './courseWork.vue'
import ChapterExam from './chapterExam.vue'

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