<!--
* @FileDescription: 选中弹窗
* @Author: 黄琪勇
* @Date:2024-03-22 15:21:44
-->
<template>
   <div class="chooseDialog">
      <div class="close" @click="close"></div>
      <div class="chooseCon" v-loading="loading">
         <img class="imgMid" src="@/img/cloudTextbooks/shu.png" />
         <div class="chooseBox" v-for="(listDetails, index) in listDetailData" :key="index">
            <div
               class="operate"
               v-show="(index === 0 && pageNum !== 0) || (index === 1 && listData.length > pageNum + 1)"
               @click="handlePage(index === 0 ? 'prev' : 'next')"
            >
               <img :src="require(`@/img/cloudTextbooks/${index === 0 ? 'left' : 'right'}.png`)" />
            </div>
            <div class="chooseList">
               <div class="listItem" v-for="item in listDetails" :key="item.id">
                  <div class="img">
                     <template v-if="item.lockFlag">
                        <img src="@/img/cloudTextbooks/jy.png" />
                     </template>
                     <template v-else>
                        <img src="@/img/cloudTextbooks/bf.png" />
                        <!-- <img src="@/img/cloudTextbooks/xm.png" /> -->
                     </template>
                  </div>
                  <div class="nameCon">
                     <div class="name">{{ item.name }}</div>
                     <div class="text" v-if="item.useNum ?? false">已使用{{ item.useNum }}次</div>
                  </div>
                  <div class="play" :class="{ disabled: item.lockFlag }" @click="item.lockFlag === true || handlePaly(item.id)">查看</div>
               </div>
            </div>
         </div>
      </div>
   </div>
</template>

<script setup lang="ts">
import { useDataDetailList } from "./useData"
const { handleGetDetailList, loading, listDetailData, listData, pageNum, handlePage } = useDataDetailList()
import router from "@/router"

const props = defineProps<{
   modalData: {
      id: string
   }
}>()
const emits = defineEmits<{
   (e: "onClose"): void
}>()

handleGetDetailList(props.modalData.id)

function close() {
   emits("onClose")
}

function handlePaly(id: string) {
   const url = router.resolve({
      name: "coursewarePlay",
      params: { id }
   }).href
   window.open(url, "_blank")
}
</script>

<style lang="scss" scoped>
.chooseDialog {
   width: 100%;
   height: 100%;
   padding: 40px;
   .close {
      position: absolute;
      top: -14px;
      right: -16px;
      width: 42px;
      height: 44px;
      cursor: pointer;
      background: url("@/img/useDialogConfirm/close.png") no-repeat;
      &:hover {
         background: url("@/img/useDialogConfirm/closeHover.png") no-repeat;
         background-size: cover;
      }
   }
   .chooseCon {
      width: 100%;
      height: 100%;
      display: flex;
      position: relative;
      .imgMid {
         position: absolute;
         left: 50%;
         top: 50%;
         transform: translate(-50%, -50%);
         z-index: 1;
      }
      .chooseBox {
         width: 50%;
         height: 100%;
         background: #f6d7c1;
         box-shadow: 0px 2px 3px 0px #a05400;
         border-radius: 17px;
         padding: 5px;
         position: relative;
         &:nth-child(2) {
            .operate {
               left: -30px;
               border-radius: 6px 0px 0px 6px;
            }
            &:hover .operate {
               opacity: 1;
            }
         }
         &:nth-child(3) {
            margin-left: 10px;
            .operate {
               right: -30px;
               border-radius: 0px 6px 6px 0px;
            }
            &:hover .operate {
               opacity: 1;
            }
         }
         .operate {
            width: 30px;
            height: 68px;
            background: #fffefb;
            position: absolute;
            top: 50%;
            transform: translate(0, -50%);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: opacity 0.28s;
            opacity: 0;
            &:hover {
               background-color: #edeff0;
            }
         }
         .chooseList {
            width: 100%;
            height: 100%;
            background: #fdf7f0;
            border-radius: 17px;
            padding: 0 40px 0 30px;
            overflow: hidden;
            .listItem {
               margin-top: 12px;
               padding: 10px 0;
               display: flex;
               justify-content: space-between;
               align-items: center;
               border-bottom: 1px solid #eaeaea;
               &:first-child {
                  margin-top: 32px;
               }
               &:last-child {
                  border-bottom: none;
               }
               .img {
                  flex-shrink: 0;
                  width: 35px;
                  height: 40%;
                  position: relative;
                  & > img:nth-child(1) {
                     width: 100%;
                  }
                  & > img:nth-child(2) {
                     position: absolute;
                     left: 0;
                     top: 0;
                     z-index: 1;
                  }
               }
               .nameCon {
                  margin-left: 7px;
                  flex-grow: 1;
                  .name {
                     font-weight: 600;
                     font-size: 16px;
                     color: #333333;
                     line-height: 22px;
                  }
                  .text {
                     font-weight: 400;
                     font-size: 12px;
                     color: #777777;
                     line-height: 17px;
                  }
               }
               .play {
                  flex-shrink: 0;
                  width: 64px;
                  height: 24px;
                  background: linear-gradient(180deg, #ffab71 0%, #ff6e45 100%);
                  border-radius: 12px;
                  line-height: 24px;
                  text-align: center;
                  font-weight: 500;
                  font-size: 12px;
                  color: #ffffff;
                  letter-spacing: 1px;
                  cursor: pointer;
                  &:hover {
                     opacity: $opacity-hover;
                  }
                  &.disabled {
                     background: linear-gradient(180deg, #d3d3d3 0%, #b5b5b5 100%);
                     cursor: not-allowed;
                     &:hover {
                        opacity: 1;
                     }
                  }
               }
            }
         }
      }
   }
}
</style>
<style lang="scss">
.modalFrame.chooseDialog {
   --modalFrameTitHeight: 0px;
   .modalFrameTitle {
      display: none !important;
   }
   .modalFrameBox {
      background: url("@/img/cloudTextbooks/bg.png") no-repeat;
      background-size: cover;
      box-shadow: none;
   }
}
</style>
