<template>
  <div class="user-guide">
    <template v-if="showVideo">
      <video
        ref="videoRef"
        autoplay
        src="@/assets/videos/guide.mp4"
        x5-playsinline="true"
        playsinline="true"
        webkit-playsinline="true"
        x-webkit-airplay="true"
        x5-video-player-type="h5-page"
        @play="showVideoPlay = false"
        @ended="showVideo = false"
      />

      <img
        v-if="$isMobile && showVideoPlay"
        class="play-icon"
        src="@/assets/images/play.png"
        @click="() => {
          videoRef?.play()
          showVideoPlay = false
        }"
      >

      <img
        class="video-skip"
        src="@/assets/images/startup-video-skip.png"
        @click="() => {
          showVideo = false
          showVideoPlay = false
        }"
      >
    </template>

    <template v-else>
      <div
        class="btn"
        @click="handleClose"
      >
        {{ curStep === 6 ? '我知道了' : '下一步' }}
      </div>
      <template v-if="curStep === 0">
        <div :class="['user-guide-1', $isMobile && 'is-mobile']" />
      </template>
      <template v-else>
        <template v-if="curStep > 1">
          <div class="guide-home">
            <div
              class="left-line"
            >
              返回首页
            </div>
          </div>

          <div class="guide-game">
            <div
              class="left-line"
            >
              游戏入口
            </div>
          </div>

          <div class="guide-guide">
            <div
              class="left-line"
            >
              操作指引
            </div>
          </div>
        </template>

        <div
          class="guide-dot"
        >
          <div
            class="left-line"
          >
            <span>场景互动</span>
          </div>
        </div>

        <div class="guide-box">
          <div class="guide-box__contain">
            <img
              src="https://4dkk.4dage.com/720yun_fd_manage/fodder/20231227_155535175.png"
            >
          </div>

          <div
            class="left-line"
          >
            <span>探索文物</span>
          </div>
        </div>

        <template v-if="curStep > 5">
          <div
            class="character"
            style="overflow: visible;"
          >
            <div class="top-line">
              对话赵孟頫
            </div>
          </div>
          <div class="character">
            <img
              class="default-frames"
              src="@/assets/images/pose1-min.png"
              alt=""
              draggable="false"
            >
          </div>
        </template>

        <template v-if="curStep > 2">
          <div class="guide-menu">
            营都人员与机构

            <div
              class="top-line"
            >
              阅读历史
            </div>
          </div>
        </template>

        <template v-if="curStep > 3">
          <div
            class="guide-tab"
            :style="guideTabStyle"
          >
            <span>帝都</span>

            <div
              class="top-line"
            >
              <p>改变场景位置</p>
            </div>
          </div>
        </template>

        <div
          v-if="curStep > 4"
          class="qhcj"
        >
          <div
            class="top-line"
          >
            切换场景
          </div>
        </div>
      </template>
    </template>
  </div>
</template>

<script setup>
import { onMounted, ref, inject } from "vue"

const curStep = ref(0)
const guideTabStyle = ref('')
const showVideo = ref(true)
const showVideoPlay = ref(true)
const videoRef = ref()
const $isMobile = inject('$isMobile')
const emits = defineEmits(['close'])

onMounted(() => {
  const dom = document.querySelector('.bg-active')
  if (dom) {
    const rect = dom.getBoundingClientRect()
    guideTabStyle.value = `width:${rect.width}px;height:${rect.height}px;top:${rect.top}px;left:${rect.left}px;display:block`
  }
})

const handleClose = () => {
  if (curStep.value > 5) {
    emits('close')
    localStorage.setItem('is-open-guide', 1)
  } else {
    curStep.value += 1
  }
}
</script>

<style lang="less" scoped>
.video-skip {
  position: absolute;
  right: 43px;
  bottom: 20px;
  width: 291px;
  cursor: pointer;
  z-index: 1;
}
.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120px;
  transform: translate(-50%, -50%);
  z-index: 1;
}
.user-guide {
  .character {
    position: absolute;
    left: -157px;
    bottom: -18px;
    margin-left: constant(safe-area-inset-left);
    margin-left: env(safe-area-inset-left);
    height: 480px;
    width: 640px;
    overflow: hidden;
    z-index: 5;

    >.default-frames{
      position: absolute;
      left: 0;
      height: 100%;
      animation-name: character-default-animation;
      animation-timing-function: steps(60, end);
      animation-duration: 2.5s;
      animation-iteration-count: infinite;
    }
    .top-line {
      margin-left: 2px;
      bottom: 550px;
    }
    img {
      width: 38400px;
    }
  }
  span,
  p {
    font-family: "Source Han Sans SC Regular" !important;
  }
}

.guide-tab {
  display: none;
  position: absolute;
  background: url('@/assets/images/camera-list-item-bg-active-1.png') no-repeat center / cover;

  span {
    position: absolute;
    left: 50%;
    bottom: 18px;
    font-size: 21px;
    color: #794A00;
    font-weight: 600;
    transform: translateX(-50%);
    letter-spacing: 9px;
    font-family: Source Han Serif CN;
  }
  .top-line {
    top: -110px;
    margin-left: -10px;
  }
}
.guide-menu {
  position: absolute;
  left: 367px;
  bottom: 306px;
  margin-left: constant(safe-area-inset-left);
  margin-left: env(safe-area-inset-left);
  padding-left: 107px;
  width: 390px;
  height: 104px;
  line-height: 104px;
  font-size: 23px;
  color: #FFF1BE;
  letter-spacing: 5px;
  box-sizing: border-box;
  font-family: Source Han Serif CN;
  background: url('@/assets/images/camera-btn-1-1-2-active.png') no-repeat center / contain;

  .top-line {
    top: -130px;
    left: 55px;
  }
}
.qhcj {
  position: absolute;
  right: 70px;
  bottom: 250px;
  width: 42px;
  height: 11px;

  .top-line {
    bottom: 0;
  }
  &::after {
    content: '';
    position: absolute;
    left: -40px;
    bottom: -230px;
    width: 120px;
    height: 120px;
    border-radius: 4px;
    box-shadow: 0px 0px 5px 0px #FFE88B;
  }
}
.guide-home {
  position: absolute;
  width: 77px;
  height: 77px;
  top: 43px;
  right: 51px;
  background: url('@/assets/images/btn-return-home-1.png') no-repeat center / contain;
  z-index: 1;
}
.guide-guide {
  position: absolute;
  width: 77px;
  height: 77px;
  top: 213px;
  right: 51px;
  background: url('@/assets/images/guide/tbn_help-min.png') no-repeat center / cover;
}
.guide-game {
  position: absolute;
  width: 77px;
  height: 77px;
  top: 128px;
  right: 51px;
  background: url('@/assets/images/btn-game-entry-page-1.png') no-repeat center / cover;
}
.guide-dot {
  position: absolute;
  top: 118px;
  right: 860px;
  width: 35px;
  height: 35px;
  background: url('@/assets/images/guide/Dots.png')  no-repeat center / contain;
  z-index: 1;
}
.guide-box {
  position: absolute;
  top: 188px;
  right: 850px;
  width: 60px;
  height: 60px;
  z-index: 1;

  &__contain {
    position: relative;
    width: inherit;
    height: inherit;
    overflow: hidden;
  }
  img {
    position: absolute;
    top: 0;
    left: 0;
    width: inherit;
    animation-name: hotspot-icon-animation;
    animation-timing-function: steps(24, end);
    animation-duration: 1s;
    animation-iteration-count: infinite;
  }
}
.top-line {
  position: absolute;
  left: 50%;
  bottom: 550px;
  height: fit-content;
  font-size: 18px;
  color: rgba(255,255,255,0.85);
  line-height: 21px;
  letter-spacing: 3px;
  white-space: nowrap;
  transform: translateX(-50%);
  text-shadow: 2px 2px 15px #C9AA79;

  &::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -10px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #FFEAA8;
    transform: translateX(-50%);
  }
  &::after {
    content: '';
    position: absolute;
    bottom: -102px;
    left: 50%;
    width: 1px;
    height: 92px;
    border-right: 1px dotted #FFEAA8;
    box-sizing: border-box;
    transform: translateX(-50%);
  }
}
.left-line {
  position: absolute;
  top: 50%;
  left: -230px;
  font-size: 18px;
  color: rgba(255,255,255,0.85);
  line-height: 21px;
  letter-spacing: 3px;
  white-space: nowrap;
  text-shadow: 2px 2px 15px #C9AA79;
  transform: translateY(-50%);

  &::before {
    content: '';
    position: absolute;
    top: 50%;
    right: -20px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #FFEAA8;
    transform: translateY(-50%);
  }
  &::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -125px;
    width: 107px;
    height: 1px;
    border-top: 1px dotted #FFEAA8;
    transform: translateY(-50%);
  }
}
.user-guide {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9999;

  .btn {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: 150px;
    width: 228px;
    height: 88px;
    line-height: 88px;
    transform: translate(-50%, -50%);
    text-align: center;
    letter-spacing: 4px;
    font-size: 21px;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    font-family: "Source Han Sans SC Regular";
    background: url('@/assets/images/guide/Rectangle346-min.png') no-repeat center / contain;
  }
  &-1 {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -100px;
    width: 509px;
    height: 294px;
    transform: translate(-50%, -50%);
    background: url("@/assets/images/guide/Group479-min.png") no-repeat center / contain;

    &.is-mobile {
      background-image: url("@/assets/images/mobile/tips_mobile-min.png");

      &::after {
        display: none;
      }
    }
    &::after {
      content: '';
      position: absolute;
      bottom: 44px;
      left: calc(50% - 10px);
      width: 116px;
      height: 116px;
      transform: translateX(-50%);
      background: url('@/assets/images/guide/icon_mouse-min.png') no-repeat center / contain;
    }
  }
  video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

@media screen and (max-height: 480px) {
  .user-guide {
    .btn,
    .left-line,
    .top-line,
    .top-line p {
      font-size: 1.5vw !important;
    }
  }

  .guide-tab span {
    font-size: 1.3vw;
  }
}
</style>
