<template>
  <div class="container">
    <Info :infoData="projectData" />
    <div class="test-container">
      <div class="title">测试结果</div>
      <div>
        <el-button>生成报告</el-button>
        <el-button>导出结果</el-button>
      </div>
    </div>

    <div class="context-container">
      <div class="left">
        <div class="title">方案选择</div>
        <div class="schemaList">
          <el-card class="category-card" v-for="item in schemaList"  :class="{ activeItem: activeSchema === item.schemeId }" @click="clickSchema(item)">
            <div class="name">{{ item.schemeName }}</div>
            <div class="icon-container">
              <div class="icon-item">
                <div class="icon-box"><img :src="timerSvg" width="16" height="16" title="响应时间">：{{ item.responseTime }}</div>
                <div class="icon-box"><img :src="scoreSvg" width="16" height="16" title="响应时间得分" />：{{ item.responseTimeScore }}</div>
              </div>
              <div class="icon-item">
                <div class="icon-box"><img :src="rateSvg" width="16" height="16" title="成功率" /> ：{{ item.successRate }}</div>
                <div class="icon-box"><img :src="scoreSvg" width="16" height="16" title="成功率得分" /> ：{{ item.successRateScore }}</div>
              </div>
            </div>
          </el-card>
        </div>
      </div>
      <div class="right">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="aeId" width="150" show-overflow-tooltip  label="结果ID" />
          <el-table-column prop="content" label="语料文本" width="260" show-overflow-tooltip  />
          <el-table-column prop="status" label="状态" show-overflow-tooltip>
            <template #default="{ row }">
              <el-tag :type="statusType[row.status] || 'info'">{{ statusTypeContext[row.status] }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="videoPath" label="视频路径" show-overflow-tooltip>
            <template #default="{ row }">
              <el-text class="mx-1" type="primary" @click="openVideoDialog(row)">播放视频</el-text>
            </template>
          </el-table-column>
          <el-table-column prop="itemResponseTime" label="响应时间" />
          <el-table-column prop="failureReason" label="失败原因"></el-table-column>
          <el-table-column prop="executionDetail" label="执行详情" />
        </el-table>
      </div>
    </div>
  
  <el-dialog v-model="centerDialogVisible" title="播放视频" width="800" center>
    <Video :src="videoSrc" />
  </el-dialog>
  </div>
</template>
<script setup>
import { onMounted } from 'vue';
import Info from './info.vue';
import { getValuationProject } from '@/api/vi/project'
import Video from '@/components/Video/index.vue'
import scoreSvg from './icon/score.svg'
import rateSvg from './icon/rate.svg'
import timerSvg from './icon/timer.svg'

const route = useRoute();

const projectData = route.query.data 
  ? JSON.parse(route.query.data) 
  : {}

const schemaList = ref([])

const tableData = ref([])

const getListScheme = async () => {
  const res = await getValuationProject(projectData.projectId)
  if (res.code === 200) {
    schemaList.value = res.data;
    activeSchema.value = schemaList.value[0]?.schemeId || null
    tableData.value = schemaList.value[0]?.itemDetails || []
  }
}

const activeSchema = ref(null)
const clickSchema = async (item) => {
  activeSchema.value = item.schemeId
  tableData.value = schemaList.value.find(i => i.schemeId === item.schemeId).itemDetails || []
}

const statusType = {
  0: 'info',
  1: 'conductedState',
  2: 'successfulState',
  3: 'danger'
}

const statusTypeContext = {
  0: '待评估',
  1: '评估中',
  2: '评估成功',
  3: '评估失败'
}

const centerDialogVisible = ref(false)
const videoSrc = ref('')
const openVideoDialog = (row) => {
  videoSrc.value = row.videoPath
  centerDialogVisible.value = true
}

onMounted(() => {
  getListScheme()
})

</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;

  .btn-container {
    background: #fff;
    margin: 4px 0;
    padding: 4px 0;
  }

  .test-container {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .title {
      font-size: 20px;
      font-weight: bold;
    }
  }

  .context-container {
    height: calc(100% - 200px);
    display: flex;
    gap: 10px;

    .left {
      width: 300px;
      
      .title {
        height: 40px;
        display: flex;
        align-items: center;
        background: #fff;
        padding-left: 12px;
        border: 1px solid #e4e7ed;
        margin-bottom: 2px;
      }

      .schemaList {
        height: calc(100% - 40px);
        overflow-y: auto;
        background: #fff;
        border: 1px solid #e4e7ed;
        border-radius: 8px;
        padding: 12px;

        .category-card {
          border-radius: 8px;
          margin-bottom: 12px;

          :deep(.el-card__body) {
            display: flex;
            justify-content: space-between;
            align-items: center;
          }
          

          .icon-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-direction: column;

            .icon-item {
              display: flex;
              align-items: center;
              width: 100%;
              cursor: pointer;

              .icon-box {
                width: 74px;
                display: flex;
                align-items: center;
              }
            }
          }
        }

        .activeItem {
          border: 2px solid #409EFF;
          background: #e7e3e3;
          border-radius: 8px;
        }
      }
    }

    .right {
      flex: 1;
    }
  }
}
</style>