<script setup lang="ts">
interface Props {
  data: any
}
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')
  }
})
</script>

<template>
  <div class="list-item">
    <div class="list-item-hd">
      <div class="icon-file" :class="genFileClassNames"></div>
      <div class="button-group">
        <div class="button icon-view" v-permission="'v1-teacher-book-view'">
          <router-link :to="`/admin/lab/book/${data.id}`" target="_blank"></router-link>
        </div>
        <div class="button icon-edit" @click="$emit('clickEdit', data)" v-permission="'v1-teacher-book-update'"></div>
      </div>
    </div>
    <div class="list-item-title">
      <h2>{{ data.name }}</h2>
      <h6>{{ data.status_name }}</h6>
    </div>
    <div class="list-item-main">
      <ol>
        <li>
          <p>文件大小：{{ data.size_name }}</p>
        </li>
        <li>
          <p>观看次数：{{ data.pv }}次</p>
        </li>
        <li>
          <p>创建人：{{ data.created_operator_name }}</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;
    }
    h6 {
      margin-left: 20px;
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 500;
      line-height: 20px;
      color: var(--main-color);
    }
  }
}
</style>
