<template>
  <div
    :class="[
      'video-wrap',
      [$liveStatusObj.PausePlay, $liveStatusObj.FinishPlay].includes(liveStatus)
        ? 'pause'
        : '',
    ]"
  >
    <div class="videoRef" ref="videoRef"></div>
    <div
      class="pause-text"
      v-if="
        [$liveStatusObj.PausePlay, $liveStatusObj.FinishPlay].includes(
          liveStatus
        )
      "
    >
      <img src="../../../assets/images/pause-icon.png" alt="" srcset="" />
      <h5>
        {{
          liveStatus === $liveStatusObj.PausePlay
            ? "主播离开一会儿，请耐心等待～"
            : "直播已结束"
        }}
      </h5>
    </div>
    <div class="plat-btn" v-if="showPlayBtn" @click="playVideo">
      <img src="../../../assets/images/normal_player.png" />
    </div>
    <div v-show="!clearScreen">
      <VideoHeader :detail="detail" :online="online" />
      <VideoFooter
        ref="videoFooterRef"
        :detail="detail"
        :activityObj="activityObj"
        :informMsgList="informMsgList"
        :isSpeak="isSpeak"
        @sendMsg="sendMsg"
        @closeActivity="closeActivity"
        @clearScreenFn="clearScreenFn"
      />
    </div>
    <img
      v-if="clearScreen"
      @click="clearScreen = !clearScreen"
      class="close-screen"
      src="@/assets/images/closeScreen.png"
    />
  </div>
</template>

<script setup>
import { ref, defineProps } from "vue";
import VideoHeader from "../components/VideoHeader.vue";
import VideoFooter from "../components/VideoFooter.vue";

import useGetLiveStatusObj from "@/hooks/useGetLiveStatusObj";

const $liveStatusObj = useGetLiveStatusObj();

defineProps({
  detail: {
    type: Object,
    default: () => ({}),
  },
  liveStatus: {
    type: Number,
  },
  isSpeak: {
    // 是否关闭互动
    type: Boolean,
    default: false,
  },
  activityObj: {
    type: Object,
    default: () => ({}),
  },
  informMsgList: {
    // 聊天互动信息
    type: Array,
    default: () => [],
  },
  showPlayBtn: {
    type: Boolean,
    default: false,
  },
  online: {
    type: Number,
  },
  closeActivity: {
    type: Function,
  },
  sendMsg: {
    type: Function,
  },
});

// 清屏操作
let clearScreen = ref(false); // 清屏
const clearScreenFn = () => {
  clearScreen.value = !clearScreen.value;
};

// let preTime = "";
// const dblclickLive = (e) => {
//   if (!preTime) {
//     preTime = new Date().getTime() / 1000;
//   } else {
//     const time = new Date().getTime() / 1000 - preTime;
//     preTime = new Date().getTime() / 1000;
//     if (time < 2) {
//       sendMsg(4);
//       const img = document.createElement("img");
//       img.setAttribute("src", "./static/images/live.png");
//       img.setAttribute("class", "live-img");
//       img.style.top = `${e.changedTouches[0].pageY}px`;
//       img.style.left = `${e.changedTouches[0].pageX}px`;
//       document.querySelector(".video-wrap").appendChild(img);
//       img.addEventListener("touchstart", (e) => {
//         dblclickLive(e);
//       });
//       ((img) => {
//         setTimeout(() => {
//           let videoWrap = document.querySelector(".video-wrap");
//           videoWrap && videoWrap.removeChild(img);
//         }, 2000);
//       })(img);
//     } else {
//       console.log("time", time);
//       preTime = "";
//     }
//   }
// };
</script>
<style scoped lang="scss">
.videoRef,
#player-container-id {
  width: 100%;
  height: 100%;
}
.video-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url(../../../assets/images/video-bg.png) no-repeat center;
  &.pause {
    background: linear-gradient(0deg, #333 0%, #333 100%);
  }
  video {
    width: 100%;
    height: 100%;
  }
  ::v-deep .video-js {
    width: 100%;
    height: 100%;
    .vjs-control-bar {
      z-index: 3;
      font-size: 18px;
    }
  }
  .pause-text {
    img {
      width: 90px;
      height: 90px;
      margin-bottom: 32px;
    }
    font-size: 28px;
    color: #cccccc;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    text-align: center;
  }
  .plat-btn {
    position: absolute;
    left: 50%;
    width: 124px;
    height: 124px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    img {
      width: 64px;
      height: 64px;
      display: flex;
    }
  }
}
.msg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  border-radius: 16px;
  background: url(../../../assets/images/msg.png) no-repeat left 24px center;
  background-size: 32px 32px;
  background-color: red;
  color: #fff;
  margin-top: 16px;
  padding: 0 24px 0 68px;
  p {
    font-size: 24px;
    color: #ffffff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .close {
    display: block;
    width: 48px;
    height: 48px;
    background: url(../../../assets/images/close.png) no-repeat center;
    background-size: 32px 32px;
    margin-left: 34px;
  }
}
.opt-wrap {
  position: absolute;
  bottom: 40px;
  padding: 0 20px;
  width: 100%;
  box-sizing: border-box;
}
.input-area {
  display: flex;
  align-items: center;
  input {
    height: 64px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 32px;
    font-weight: 500;
    font-size: 24px;
    letter-spacing: 0;
    line-height: 24px;
    padding: 0 16px;
    flex: 1;
    color: #cccccc;
  }

  input::placeholder {
    color: #cccccc; /* 设置颜色为灰色 */
  }
  button {
    width: 64px;
    height: 64px;
    margin-left: 20px;
  }
  .star {
    position: relative;
    background: url(../../../assets/images/like-icon1.png) no-repeat center;
    background-size: cover;
    &.active {
      background: url(../../../assets/images/like-icon2.png) no-repeat center;
      background-size: cover;
    }
    span {
      position: absolute;
      top: 0;
      right: 0;
      min-width: 20px;
      transform: translateX(50%) translateY(-50%);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 4px;
      flex-direction: column;
      border-radius: 13px 13px 13px 4px;
      background: linear-gradient(
        128deg,
        #fff2dc -25.5%,
        #ffd9a7 89.14%,
        #605a52 89.14%
      );
      color: rgb(142, 81, 5);
      font-size: 18px;
      font-style: normal;
      font-weight: 500;
    }
  }
  .clear {
    background: url(../../../assets/images/clear.png) no-repeat center;
    background-size: cover;
  }
  .share {
    background: url(../../../assets/images/share.png) no-repeat center;
    background-size: cover;
  }
  .shop {
    background: url(../../../assets/images/shop.png) no-repeat center;
    background-size: cover;
  }
}
.interact-scroll {
  position: relative;
  max-height: 400px;
  overflow: hidden;
  text-align: left;
  width: calc(100% - 238px);
  margin-right: 20px;
  li > div {
    display: flex;
    align-items: center;
    font-size: 24px;
    font-weight: 500;
    letter-spacing: 0;
    text-align: left;
    color: #fff;
    margin-bottom: 12px;
    label {
      color: rgba(154, 191, 255, 1);
    }
    &.product-item {
      flex-direction: column;
      align-items: flex-start;
    }
  }
  p,
  .reply-content {
    line-height: 28px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 16px;
  }
  .reply {
    line-height: 40px;
  }
  button {
    height: 44px;
    line-height: 44px;
    border: none;
    border-radius: 20px;
    background-color: rgba(0, 0, 0, 0.3);
    background-repeat: no-repeat;
    background-position: left 16px center;
    background-size: 20px auto;
    margin-left: 10px;
    padding-left: 32px;
    font-size: 24px;
    padding: 0 20px 0 36px;
    &.share {
      color: #ff3d36;
      background-image: url(../../../assets/images/share-icon2.png);
    }
    &.attention {
      color: #ff7d26;
      background-image: url(../../../assets/images/attention.png);
    }
  }
}
.msg-content {
  display: flex;
  align-items: flex-end;
  margin-bottom: 20px;
  .recommend-img {
    position: relative;
    width: 208px;
    height: 280px;
    margin-right: 10px;
    img {
      width: 100%;
      height: 100%;
    }
    i {
      position: absolute;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      top: 0;
      right: 0;
      transform: translateX(50%) translateY(-50%);
      background: url(../../../assets/images/close-icon.png) no-repeat center;
      background-size: 100%;
    }
  }
}
.close-screen {
  position: absolute;
  bottom: 144px;
  right: 20px;
  width: 64px;
  height: 64px;
}
::v-deep .van-dialog__header {
  color: rgb(51, 51, 51);
  text-align: center;
  font-size: 36px;
  font-style: normal;
  font-weight: 500;
}
.dialog-content {
  padding: 40px 32px;
  p {
    color: rgb(27, 35, 48);
    text-align: center;
    font-size: 32px;
    font-weight: 400;
    line-height: 48px;
    margin-bottom: 24px;
  }
  input {
    width: 100%;
    box-sizing: border-box;
    padding: 24px;
    align-items: center;
    border-radius: 12px;
    background: var(---, #f8f9fa);
    color: rgb(179, 179, 179);
    font-size: 32px;
    font-weight: 400;
  }
}
::v-deep .live-img {
  position: absolute;
  width: 120px;
  height: auto;
  z-index: 2;
  transform: translateX(-50%) translateY(-100%);
  animation: mymove 2s;
  -webkit-animation: mymove 2s; /*Safari and Chrome*/
}

@keyframes mymove {
  from {
    transform: translateX(-50%) translateY(-100%) scale(1);
    opacity: 1;
  }
  to {
    transform: translateX(-50%) translateY(-100%) scale(2);
    opacity: 0;
  }
}

@-webkit-keyframes mymove /*Safari and Chrome*/ {
  from {
    transform: translateX(-50%) translateY(-100%) scale(1);
    opacity: 1;
  }
  to {
    transform: translateX(-50%) translateY(-100%) scale(2);
    opacity: 0;
  }
}
::v-deep .tcp-playlist {
  z-index: 2;
}
</style>
