<script setup lang="ts">
import type { Contest } from '../types'
import { contestMode } from '@/utils/dictionary'
interface Props {
  data: Contest
}
const props = defineProps<Props>()

const isMy = $computed(() => {
  return !!props.data.login_id
})

const typeText = $computed(() => {
  return contestMode[props.data.type]
})
</script>

<template>
  <div class="contest-item">
    <div class="contest-item-main">
      <div class="contest-item-main__bg"><img :src="data.cover" /></div>
      <div class="contest-item-main__inner">
        <img :src="data.logo" class="logo" />
        <div class="cover">
          <ul class="info-list" v-if="isMy">
            <li>姓名：{{ data.student_name }}</li>
            <li>参赛ID：{{ data.login_id }}</li>
            <li>参赛形式：{{ typeText }}</li>
            <li>所属学校：{{ data.org_name }}</li>
          </ul>
          <router-link :to="`/student/contest/lab/${data.id}?name=${data.name}`" v-if="isMy">
            <el-button round type="primary">我要训练</el-button>
          </router-link>
          <router-link :to="{ path: '/student/contest/join', query: { id: data.id, name: data.name } }" v-else>
            <el-button round type="primary">我要报名</el-button>
          </router-link>
        </div>
      </div>
    </div>
    <div class="contest-item-name">{{ data.name }}</div>
  </div>
</template>

<style lang="scss">
.contest-item-main {
  position: relative;
  height: 200px;
  border-radius: 10px;
  overflow: hidden;
}
.contest-item-main__bg {
  width: 100%;
  height: 100%;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.5;
  }
}
.contest-item-main__inner {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 1;
  .logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  &:hover {
    .cover {
      display: flex;
    }
  }
  .cover {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.7);
    .info-list {
      padding: 10px;
      font-size: 14px;
      color: #fff;
      line-height: 24px;
    }
  }
}
.contest-item-name {
  margin-top: 10px;
  padding: 10px;
  font-size: 16px;
  color: #fff;
  text-align: center;
  background-color: var(--main-color);
  border-radius: 10px;
}
</style>
