<template>
  <div class="vuln-detail-container">
    <div class="vuln-title mb-2">{{ vulnDetail.vulnId }}</div>
    <div class="vuln-sub-title mb-3">
      <span>{{ vulnDetail.cweId || '--' }}</span>
      <span class="split-line"></span>
      <span><span class="release-time">发布时间：</span>{{ vulnDetail.publishDate || '--' }}</span>
    </div>
    <Card simple class="jyh-card mb-4">
      <div class="card-title">漏洞名称</div>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">漏洞名称</span>
          <span class="card-val">{{vulnDetail.vulnId || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">关联漏洞编号</span>
          <span class="card-val">{{vulnDetail.cweId || '--'}}</span>
        </d-col>
      </d-row>
      <d-row class="mb-3">
        <d-col :span="24">
          <span class="card-key width-90">简介</span>
          <span class="card-val">{{vulnDetail.description || '--'}}</span>
        </d-col>
      </d-row>
      <d-row class="mb-3">
        <d-col :span="24">
          <span class="card-key width-90">额外信息</span>
          <span class="card-val">
            <span class="card-val">{{vulnDetail.extraInfo || '--'}}</span>
          </span>
        </d-col>
      </d-row>
      <d-row>
        <d-col :span="24">
          <span class="card-key width-90">补丁链接</span>
          <span class="card-val">
            <span class="card-val">{{vulnDetail.patchLink || '--'}}</span>
          </span>
        </d-col>
      </d-row>
    </Card>
    <Card simple class="jyh-card mb-4">
      <div class="card-title">安全漏洞</div>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">严重性</span>
          <span class="card-val">{{vulnDetail.severity || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">分值</span>
          <span class="card-val">{{vulnDetail.cvssScore || '--'}}</span>
        </d-col>
      </d-row>
    </Card>
    <Card simple class="jyh-card mb-4">
      <div class="card-title">安全问题</div>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">攻击向量</span>
          <span class="card-val">{{vulnDetail.attackVector || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">攻击复杂度</span>
          <span class="card-val">{{vulnDetail.attackComplexity || '--'}}</span>
        </d-col>
      </d-row>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">用户交互</span>
          <span class="card-val">{{vulnDetail.userInteraction || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">需要特殊权限</span>
          <span class="card-val">{{vulnDetail.privilegesRequired || '--'}}</span>
        </d-col>
      </d-row>
    </Card>
    <Card simple class="jyh-card mb-4">
      <div class="card-title">影响的组件</div>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">组件名</span>
          <span class="card-val">{{componentInfo.moduleName || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">深度</span>
          <span class="card-val">{{componentInfo.depth || '--'}}</span>
        </d-col>
      </d-row>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">当前版本</span>
          <span class="card-val">{{componentInfo.currentVersion || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">最新版本</span>
          <span class="card-val">{{componentInfo.latestVersion || '--'}}</span>
        </d-col>
      </d-row>
      <d-row>
        <d-col :span="24">
          <span class="card-key width-90">组件依赖关系</span>
          <span class="card-val">{{componentInfo.version || '--'}}</span>
        </d-col>
      </d-row>
    </Card>
    <Card simple class="jyh-card mb-4">
      <div class="card-title">修复建议</div>
      <d-row class="mb-3">
        <d-col :span="12">
          <span class="card-key width-90">补丁版本</span>
          <span class="card-val">{{remediationInfo.recommendedVersion || '--'}}</span>
        </d-col>
        <d-col :span="12">
          <span class="card-key width-90">修复兼容性</span>
          <span class="card-val">{{remediationInfo.compatibility || '--'}}</span>
        </d-col>
      </d-row>
      <d-row>
        <d-col :span="24">
          <span class="card-key width-90">修复建议</span>
          <span class="card-val">{{remediationInfo.recommendedFix || '--'}}</span>
        </d-col>
      </d-row>
    </Card>
  </div>
</template>

<script setup lang="ts">
import { getVulnDetail } from '@/api/jyh';
import { ref } from 'vue';

const propsData = defineProps(['softwareId', 'vulnId', 'vulnInfo']);
const vulnDetail = ref({});
const componentInfo = ref({});
const remediationInfo = ref({})

const queryVulnDetail = async () => {
  const data = await getVulnDetail({softwareId: propsData.softwareId, id: propsData.vulnId});
  if (data?.data?.data?.data) {
    vulnDetail.value = data.data.data.data.vulnerabilityInfo;
    componentInfo.value = data.data.data.data.componentInfo;
    remediationInfo.value = data.data.data.data.remediationInfo;
  }
};
queryVulnDetail();
</script>

<style scoped lang="scss">
.vuln-detail-container {
  width: 800px;
  padding: 20px;

  .vuln-title {
    color: #191919;
    font-family: HarmonyOS Sans SC;
    font-weight: 400;
    font-size: 18px;
  }

  .vuln-sub-title {
    color: #191919;
    font-family: HarmonyOS Sans;
    font-weight: regular;
    font-size: 12px;
    line-height: 20px;
    letter-spacing: 0px;
    text-align: left;

    .split-line {
      width: 1px;
      display: inline-block;
      line-height: 16px;
      height: 16px;
      vertical-align: middle;
      margin: 0 8px;
      background-color: #EEF0F5;
    }

    .release-time {
      color: #808080;
    }
  }

  .card-val {
    display: inline-block;
    width: calc(100% - 90px);
    vertical-align: top;
  }
}
</style>