<script setup lang="ts">
import type { BookItem } from '../types'
import Preview from '@/components/Preview.vue'

import { getBook } from '../api'

interface Props {
  id: string
}
const props = defineProps<Props>()

let detail = $ref<BookItem | null>(null)
provide('detail', $$(detail))
function fetchInfo() {
  if (!props.id) return
  getBook({ id: props.id }).then(res => {
    detail = res.data
  })
}
onMounted(() => {
  fetchInfo()
})
</script>

<template>
  <AppCard title="查看实验指导书">
    <template v-if="detail">
      <el-descriptions>
        <el-descriptions-item label="实验指导书名称：">{{ detail.name }}</el-descriptions-item>
        <el-descriptions-item label="文件大小：">{{ detail.size_name }}</el-descriptions-item>
        <el-descriptions-item label="观看次数：">{{ detail.pv }}次</el-descriptions-item>
        <el-descriptions-item label="关联实验课程：">{{ detail.course_id_name }}</el-descriptions-item>
        <el-descriptions-item label="关联实验：">{{ detail.experiment_id_name }}</el-descriptions-item>
        <el-descriptions-item label="有效状态：">{{ detail.status_name }}</el-descriptions-item>
        <el-descriptions-item label="创建人：">{{ detail.created_operator_name }}</el-descriptions-item>
        <el-descriptions-item label="创建时间：">{{ detail.created_time }}</el-descriptions-item>
      </el-descriptions>
      <div style="height: 80vh">
        <Preview :url="detail.url"></Preview>
      </div>
    </template>
  </AppCard>
</template>
