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

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

let detail = $ref<ExperimentBookType>()
function fetchInfo() {
  getExperimentBook({ competition_id: props.competition_id }).then(res => {
    detail = res.data.detail
  })
}
watchEffect(() => {
  fetchInfo()
})

const isEmpty = $computed(() => {
  return !props.competition_id || !detail?.id
})

const file = $computed(() => {
  if (!detail) return {}
  return JSON.parse(detail.url)
})
</script>

<template>
  <el-empty description="暂无数据" v-if="isEmpty" />
  <template v-else>
    <Preview :url="file.url"></Preview>
  </template>
</template>
