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

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

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

const isEmpty = $computed(() => {
  return !props.experiment_id || !detail?.id
})
</script>

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