<script setup lang="ts">
import { useCookies } from '@vueuse/integrations/useCookies'
import { getExperimentExam } from '../api'

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

const route = useRoute()
const cookies = useCookies()

const list = ref<any[]>([])

// 当前选中的考试
const currentExam = computed(() => {
  return list.value[0]
})

// 考试平台 URL
const examURL = computed(() => {
  if (!currentExam.value) return ''
  return `${import.meta.env.VITE_EXAM_SHOW_URL}/exam/${currentExam.value?.exam_id}?has_time=0&has_submit=0&has_save=1&show_answer=1`
  // return `https://dev.ezijing.com:5173/exam/7003551966412406784?has_time=0&has_submit=0&has_save=1&show_answer=1`
})

async function fetchInfo() {
  const res = await getExperimentExam({ competition_id: props.competition_id, platform_key: route.query?.type as string, project: 'x1' })
  const resCookies = res.data.cookies
  cookies.set(resCookies.key, resCookies.auth_key, { domain: '.ezijing.com', path: '/' })
  list.value = res.data.items || []
}
onMounted(() => {
  fetchInfo()
})
</script>

<template>
  <iframe class="iframe" :src="examURL" frameborder="0" v-if="currentExam"></iframe>
  <el-empty description="暂无数据" v-else />
</template>
