<template>
  <div class="exam-detail">
    <div class="exam-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/exam' }">考试中心</el-breadcrumb-item>
        <el-breadcrumb-item>考试详情</el-breadcrumb-item>
      </el-breadcrumb>
      
      <h1 class="exam-title">{{ exam.title }}</h1>
      
      <div class="exam-info">
        <div class="info-item">
          <span class="label">考试时间：</span>
          <span>{{ exam.startTime }} 至 {{ exam.endTime }}</span>
        </div>
        <div class="info-item">
          <span class="label">考试时长：</span>
          <span>{{ exam.duration }}分钟</span>
        </div>
        <div class="info-item">
          <span class="label">总分：</span>
          <span>{{ exam.totalScore }}分</span>
        </div>
        <div class="info-item">
          <span class="label">及格分数：</span>
          <span>{{ exam.passScore }}分</span>
        </div>
      </div>
    </div>
    
    <div class="exam-notice">
      <h2>考试须知</h2>
      <div class="notice-content">
        <p>1. 考试时间内可随时参加考试，请合理安排时间。</p>
        <p>2. 考试开始后，计时器会自动计时，请在规定时间内完成考试。</p>
        <p>3. 考试过程中请勿刷新页面或关闭浏览器，否则可能导致答案丢失。</p>
        <p>4. 提交试卷后将立即显示考试成绩，请仔细检查后再提交。</p>
      </div>
    </div>
    
    <div class="exam-action">
      <el-button type="primary" size="large" @click="startExam">开始考试</el-button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'

const route = useRoute()
const router = useRouter()
const examId = route.params.id

const exam = ref({
  id: examId,
  title: '天气预报分析能力评估',
  startTime: '2023-08-01 09:00',
  endTime: '2023-09-01 18:00',
  duration: 120,
  totalScore: 100,
  passScore: 60,
  status: 'ongoing'
})

onMounted(() => {
  // 在实际应用中，这里应该根据examId从API获取考试详情
  console.log('加载考试ID:', examId)
})

const startExam = () => {
  ElMessageBox.confirm(
    `您即将开始"${exam.value.title}"考试，考试时长${exam.value.duration}分钟，确认开始吗？`,
    '开始考试',
    {
      confirmButtonText: '确认开始',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      // 跳转到考试页面
      router.push(`/exam/${examId}/paper`)
    })
    .catch(() => {
      // 用户取消
    })
}
</script>

<style lang="scss" scoped>
.exam-detail {
  max-width: 800px;
  margin: 0 auto;
  
  .exam-header {
    margin-bottom: 20px;
    
    .exam-title {
      font-size: 24px;
      margin: 15px 0;
    }
    
    .exam-info {
      background: white;
      border-radius: 8px;
      padding: 20px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      
      .info-item {
        margin-bottom: 10px;
        
        &:last-child {
          margin-bottom: 0;
        }
        
        .label {
          font-weight: bold;
          margin-right: 10px;
        }
      }
    }
  }
  
  .exam-notice {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    
    h2 {
      font-size: 18px;
      margin-bottom: 15px;
    }
    
    .notice-content {
      p {
        margin-bottom: 10px;
        line-height: 1.6;
      }
    }
  }
  
  .exam-action {
    text-align: center;
    margin-top: 30px;
  }
}
</style> 