<script setup lang="ts">
import type { CaseItem } from '../types'
import { useMapStore } from '@/stores/map'

interface Props {
  data: CaseItem
}
const props = defineProps<Props>()

const genFileClassNames = $computed(() => {
  const extName = props.data.url?.split('.').pop() || ''
  return {
    'icon-file__word': extName.includes('doc'),
    'icon-file__excel': extName.includes('xls'),
    'icon-file__ppt': extName.includes('ppt'),
    'icon-file__pdf': extName.includes('pdf')
  }
})

const username = computed(() => {
  const operator = props.data.created_operator
  return operator.real_name || operator.nickname || operator.username
})

// 数据状态
const status = useMapStore().getMapValuesByKey('system_status')
const statusName = computed(() => {
  return status.find(item => item.value === props.data.status)?.label
})

const sizeName = computed(() => {
  return props.data.size + 'MB'
})
</script>

<template>
  <div class="list-item">
    <div class="list-item-hd">
      <div class="icon-file" :class="genFileClassNames"></div>
      <div class="button-group">
        <el-tooltip effect="dark" content="查看">
          <div class="button icon-view" v-permission="'teacher-experiment-cases-detail'">
            <router-link :to="`/admin/lab/case/${data.id}`" target="_blank"></router-link>
          </div>
        </el-tooltip>
        <el-tooltip effect="dark" content="编辑">
          <div
            class="button icon-edit"
            @click="$emit('clickEdit', data)"
            v-permission="'teacher-experiment-cases-update'"
          ></div>
        </el-tooltip>
      </div>
    </div>
    <div class="list-item-title">
      <h2>{{ data.name }}</h2>
      <h6>{{ statusName }}</h6>
    </div>
    <div class="list-item-main">
      <ol>
        <li>
          <p>文件大小：{{ sizeName }}</p>
        </li>
        <li>
          <p>观看次数：{{ data.pv }}次</p>
        </li>
        <li>
          <p>创建人：{{ username }}</p>
        </li>
        <li>
          <p>创建时间：{{ data.created_time }}</p>
        </li>
        <li>
          <p>更新时间：{{ data.updated_time }}</p>
        </li>
      </ol>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.list-item {
  position: relative;
  padding: 30px;
  background: linear-gradient(to bottom left, rgba(186, 20, 62, 0.1) 0%, rgba(255, 255, 255, 0.8) 60%);
  border-radius: 12px;
  &:hover {
    box-shadow: 0 3px 18px rgba(0, 0, 0, 0.27);
  }
  .list-item-hd {
    display: flex;
    justify-content: space-between;
    .button-group {
      display: flex;
      .button {
        a {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      .button + .button {
        margin-left: 12px;
      }
    }
  }
  .icon-file {
    width: 30px;
    height: 30px;
    background: url(@/assets/images/icon_word.png) no-repeat;
    background-size: contain;
  }
  .icon-file__word {
    background: url(@/assets/images/icon_word.png) no-repeat;
    background-size: contain;
  }
  .icon-file__excel {
    background: url(@/assets/images/icon_excel.png) no-repeat;
    background-size: contain;
  }
  .icon-file__ppt {
    background: url(@/assets/images/icon_ppt.png) no-repeat;
    background-size: contain;
  }
  .icon-file__pdf {
    background: url(@/assets/images/icon_pdf.png) no-repeat;
    background-size: contain;
  }
  .icon-edit {
    width: 16px;
    height: 16px;
    background: url(@/assets/images/icon_edit.png) no-repeat;
    background-size: contain;
    cursor: pointer;
  }
  .icon-view {
    width: 16px;
    height: 16px;
    background: url(@/assets/images/icon_view.png) no-repeat;
    background-size: contain;
    cursor: pointer;
  }
  .list-item-main {
    line-height: 30px;
    ol {
      margin-left: 20px;
    }
    li {
      margin-top: 24px;
      font-size: 16px;
      line-height: 1;
      color: var(--main-color);
      list-style: disc;
    }
    p {
      color: #666;
    }
  }
  .list-item-title {
    margin: 26px 0 36px;
    display: flex;
    justify-content: space-between;
    h2 {
      flex: 1;
      font-size: 18px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      line-height: 20px;
      color: #333333;
      word-break: break-all;
    }
    h6 {
      margin-left: 20px;
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 500;
      line-height: 20px;
      color: var(--main-color);
    }
  }
}
</style>
