<template>
  <file-panel :title="chapter.name" :files="files"></file-panel>
</template>

<script>
import FilePanel from './filePanel.vue'
export default {
  name: 'ViewerFile',
  components: { FilePanel },
  props: {
    // 当前选中的
    chapter: { type: Object, default: () => {} },
    // 课程详情接口返回的数据
    data: { type: Object, default: () => {} }
  },
  computed: {
    files() {
      // 课程资料
      if (this.chapter.id === 'course_info') {
        return this.data.files || []
      }
      // 章节资料
      if (this.chapter.reading) {
        const reading = this.chapter.reading
        const file = {
          file_name: reading.reading_content,
          file_url: reading.reading_attachment
        }
        return [file]
      }
      return []
    }
  }
}
</script>
