<template>
  <div
    class="relic-detail"
    :class="{
      isDarkTheme,
      notDarkTheme: !isDarkTheme,
    }"
  >
    <el-switch
      v-if="$route.query['hide-theme-switch'] !== '1'"
      :model-value="isDarkTheme"
      class="theme-switch"
      :size="$isMobile ? '' : 'large'"
      inline-prompt
      :active-icon="Moon"
      :inactive-icon="Sunny"
      @update:modelValue="onThemeChange"
    />
    <article
      class="desc"
      :class="{
        isDarkTheme,
        notDarkTheme: !isDarkTheme,
      }"
    >
      <h1
        v-if="$route.query['hide-name'] !== '1'"
        v-html="title"
      />
      <div
        v-show="!$isMobile && isShowDescDetail"
        class="splitter"
      />
      <div
        v-show="!$isMobile && isShowDescDetail"
        class="detail"
        v-html="detail"
      />
    </article>
    <div
      v-show="$isMobile && isShowDescDetail"
      class="desc-for-mobile"
    >
      <button
        class="close"
        @click="isShowDescDetail = false"
      >
        <img
          src="@/assets/images/btn-close.png"
          alt=""
          draggable="false"
        >
      </button>
      <h1 v-html="title" />
      <div
        class="detail"
        v-html="detail"
      />
    </div>
    <!-- 假的阴影 -->
    <!-- <img
      class="relic-shadow"
      src="@/assets/images/relic-shadow.png"
      alt=""
      draggable="false"
    > -->

    <transition name="fade-out">
      <img
        v-if="isShowLogo && $route.query['hide-logo'] !== '1'"
        :src="require(`@/assets/images/logo-for-${isDarkTheme ? 'dark' : 'light'}-theme.png`)"
        alt=""
        class="logo"
        draggable="false"
      >
    </transition>

    <menu>
      <!-- <button class="go-homepage">
        <img
          :src="require(`@/assets/images/btn-home-${isDarkTheme ? 'dark' : 'light'}.png`)"
          alt=""
          draggable="false"
        >
      </button> -->
      <button
        v-if="$route.query['hide-detail-display-button'] !== '1'"
        class="show-detail"
        @click="onClickShowDetail"
      >
        <img
          :src="require(`@/assets/images/btn-desc-${isDarkTheme ? 'dark' : 'light'}${isShowDescDetail ? '-active' : ''}.png`)"
          alt=""
          draggable="false"
        >
      </button>
      <button
        v-if="$route.query['hide-help-button'] !== '1'"
        class="show-help"
        @click="onClickShowHelp"
      >
        <img
          :src="require(`@/assets/images/btn-help-${isDarkTheme ? 'dark' : 'light'}${isShowHelp ? '-active' : ''}.png`)"
          alt=""
          draggable="false"
        >
      </button>
      <button
        v-if="$route.query['hide-share-button'] !== '1'"
        v-click-outside.click="onClickOutsideShare"
        class="share"
        @click="isShowShareMenu = !isShowShareMenu"
      >
        <img
          :src="require(`@/assets/images/btn-share-${isDarkTheme ? 'dark' : 'light'}${isShowShareMenu ? '-active' : ''}.png`)"
          alt=""
          draggable="false"
        >
        <div
          class="inner-menu social-share"
          data-sites="wechat, weibo, qq"
          :style="{
            height: isShowShareMenu ? '154px' : '100%',
            opacity: isShowShareMenu ? '1' : '0',
            backgroundColor: isDarkTheme ? '#555' : '#ccc',
          }"
        />
      </button>
    </menu>

    <button
      v-if="$route.query['hide-arrow'] !== '1'"
      v-show="hasPrevious"
      class="jump previous"
      @click="onClickPrevious"
    >
      <img
        class=""
        src="@/assets/images/btn-arrow-left.png"
        alt=""
        draggable="false"
      >
    </button>
    <button
      v-if="$route.query['hide-arrow'] !== '1'"
      v-show="hasNext"
      class="jump next"
      @click="onClickNext"
    >
      <img
        class=""
        src="@/assets/images/btn-arrow-right.png"
        alt=""
        draggable="false"
      >
    </button>

    <help-comp
      v-show="isShowHelp"
      @close="isShowHelp = false"
    />
  </div>
</template>

<script>
import { Moon, Sunny } from '@element-plus/icons-vue'
import { mapMutations, mapState } from 'vuex'
import HelpComp from "@/components/HelpComp.vue"

export default {
  components: {
    HelpComp,
  },
  data() {
    return {
      isShowDescDetail: false,
      isShowLogo: true,
      isShowHelp: false,
      title: this.$gConfigInfo.modelList[this.$route.query.m],
      detail: this.$gConfigTxt[this.$route.query.m],
      isShowShareMenu: false,
    }
  },
  computed: {
    ...mapState([
      'isDarkTheme',
    ]),
    id() {
      return this.$route.query.m
    },
    Sunny() {
      return Sunny
    },
    Moon() {
      return Moon
    },
    relicIndex() {
      return Object.keys(this.$gConfigInfo.modelList).indexOf(this.$route.query.m)
    },
    hasPrevious() {
      return this.relicIndex !== 0
    },
    hasNext() {
      return this.relicIndex !== Object.keys(this.$gConfigInfo.modelList).length - 1
    },
  },
  watch: {
    id: {
      handler() {
        location.reload()
      }
    }
  },
  created() {
    if (this.$gConfigInfo.autoRotate) {
      window.autoRotate = true
    }
    fdage.embed('user-config/4dage/' + this.$route.query.m + '.4dage', {
      width: 800, // 看起来没用
      height: 600, // 看起来没用
      autoStart: true,
      fullFrame: true,
      pagePreset: false
    })
    document.addEventListener('model-loaded', this.onModelLoad)
  },
  mounted() {
    setTimeout(() => {
      window.socialShare('.social-share')
    }, 1000)
  },
  beforeUnmount() {
    const fdageUIElem = document.querySelector('#fdageUI')
    if (fdageUIElem && fdageUIElem.parentNode) {
      fdageUIElem.parentNode.parentNode.removeChild(fdageUIElem.parentNode)
    }
  },
  methods: {
    ...mapMutations([
      'setIsDarkTheme'
    ]),
    onThemeChange(v) {
      this.setIsDarkTheme(v)
    },
    onModelLoad() {
      this.isShowLogo = false
    },
    onClickShowDetail() {
      this.isShowDescDetail = !this.isShowDescDetail
    },
    onClickShowHelp() {
      this.isShowHelp = !this.isShowHelp
    },
    onClickPrevious: utils.debounce(function() {
      this.$router.replace({
        name: this.$route.name,
        query: {
          m: Object.keys(this.$gConfigInfo.modelList)[this.relicIndex - 1]
        }
      })
    }, 1000),
    onClickNext: utils.debounce(function() {
      this.$router.replace({
        name: this.$route.name,
        query: {
          m: Object.keys(this.$gConfigInfo.modelList)[this.relicIndex + 1]
        }
      })
    }, 1000),
    onClickOutsideShare() {
      this.isShowShareMenu = false
    }
  },
}
</script>

<style lang="less" scoped>
.relic-detail {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  &.isDarkTheme {
    background: #303030;
  }
  &.notDarkTheme {
    background-image: url(@/assets/images/relic-bg-light.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
  }
  > .theme-switch {
    position: absolute;
    top: 56px;
    right: 56px;
    z-index: 1;
  }
  > article.desc {
    position: absolute;
    top: 110px;
    left: 110px;
    max-width: 503px;
    width: 25vw;
    z-index: 1;
    pointer-events: none;
    &.isDarkTheme {
      color: #fff;
    }
    &.notDarkTheme {
      color: #585858;
    }
    > h1 {
      font-size: 32px;
      font-family: Source Han Serif CN-Heavy, Source Han Serif CN;
      font-weight: 800;
      line-height: 64px;
    }
    > .splitter {
      width: 100%;
      border-top: 1px dashed rgba(255,255,255,0.32);
      margin-top: 33px;
      margin-bottom: 29px;
    }
    > .detail {
      max-height: 500px;
      overflow: auto;
      padding-right: 10px;
      font-size: 20px;
      line-height: 40px;
    }
  }
  > .relic-shadow {
    position: absolute;
    bottom: 104px;
    left: 50%;
    transform: translateX(-50%);
    width: 824px;
    height: 55.82px;
  }
  > img.logo {
    position: absolute;
    bottom: 59px;
    left: 50%;
    transform: translateX(-50%);
    width: 229.57px;
    pointer-events: none;
    z-index: 1;
  }
  > menu {
    position: absolute;
    bottom: 67px;
    right: 79px;
    z-index: 1;
    > button {
      width: 32px;
      height: 32px;
      margin-left: 16px;
      > img {
        width: 100%;
        height: 100%;
      }
    }
    > button.share {
      position: relative;
      > .inner-menu {
        position: absolute;
        left: 0;
        width: 100%;
        bottom: 0;
        border-radius: calc(32px / 2);
        transition: all 0.2s;
        z-index: -1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-evenly;
        padding-top: 5px;
        padding-bottom: 35px;
        > button {
          width: 27px;
          height: 27px;
          background-size: cover;
          background-repeat: no-repeat;
          background-position: center center;
        }
      }
    }
  }

  > button.jump {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    width: 74px;
    height: 74px;
    &.previous {
      left: 20px;
    }
    &.next {
      right: 20px;
    }
    > img {
      width: 100%;
      height: 100%;
    }
  }

  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-thumb { background: #fff; }
  ::-webkit-scrollbar-button { display: none; }
  ::-webkit-scrollbar-track { background: #000; }
  // 横竖滚动条轨道交汇处
  ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-resizer { background: transparent; }
}



.mobile {
  .relic-detail {
    &.isDarkTheme {
    }
    &.notDarkTheme {
    }
    > .theme-switch {
      top: 4vw;
      right: -4vw;
      transform: rotate(90deg);
      transform-origin: 0 0;
    }
    > article.desc {
      position: absolute;
      top: 12.7%;
      left: 12vw;
      writing-mode: vertical-lr;
      max-height: 75%;
      pointer-events: none;
      &.isDarkTheme {
        > h1 {
          text-decoration-color: #3e3e3e;
        }
      }
      &.notDarkTheme {
        > h1 {
          text-decoration-color: #d9dadb;
        }
      }
      > h1 {
        font-size: 4vw;
        font-weight: 800;
        line-height: 5vw;
        text-decoration-line: underline;
        text-underline-offset: 8px;
        text-underline-position: right;
      }
    }
    > .desc-for-mobile {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 2;
      background: rgba(0,0,0,0.3);
      backdrop-filter: blur(10px);
      padding: 20vw;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: flex-start;
      > button.close {
        position: absolute;
        top: 9vw;
        right: 5vw;
        width: 8vw;
        height: 8vw;
        > img {
          width: 100%;
          height: 100%;
        }
      }
      > h1 {
        font-size: 4vw;
        font-family: Source Han Serif CN-Heavy, Source Han Serif CN;
        font-weight: 800;
        color: #FFFFFF;
        line-height: 7vw;
      }
      > .detail {
        margin-top: 1em;
        font-size: 2vw;
        font-family: PingFang HK-Semibold, PingFang HK;
        font-weight: 600;
        color: #FFFFFF;
        line-height: 5vw;
      }
    }
    > .relic-shadow {
      position: absolute;
      bottom: 104px;
      left: 50%;
      transform: translateX(-50%);
      width: 824px;
      height: 55.82px;
    }
    > img.logo {
      bottom: 4.2%;
      width: 31vw;
      height: 6vw;
      pointer-events: none;
      z-index: 1;
    }
    > menu {
      bottom: 22.2%;
      right: 7vw;
      > button {
        display: block;
        width: 7vw;
        height: 7vw;
        margin-left: initial;
        margin-top: 3vw;
        > img {
        }
      }
      > button.share {
        display: none;
      }
    }

    > button.jump {
      top: 85%;
      transform: translateY(-50%);
      width: 10vw;
      height: 10vw;
      &.previous {
        left: 6vw;
      }
      &.next {
        right: 6vw;
      }
      > img {
      }
    }

    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-thumb { background: #fff; }
    ::-webkit-scrollbar-button { display: none; }
    ::-webkit-scrollbar-track { background: #000; }
    // 横竖滚动条轨道交汇处
    ::-webkit-scrollbar-corner { background: transparent; }
    ::-webkit-scrollbar-resizer { background: transparent; }
  }
}
</style>
<style lang="less">
* {
  --el-switch-on-color: transparent;
  --el-switch-off-color: transparent;
  --el-switch-border-color: #a3a2a2;

  .el-switch--large.is-checked .el-switch__core .el-switch__inner {
    padding: 0 0px 0 28px !important;
  }
  .el-switch--large .el-switch__core .el-switch__inner {
    padding: 0 27px 0 1px !important;
  }

  .el-switch .el-switch__core .el-switch__action {
    z-index: -1;
    background-color: #000 !important;
  }
  .el-switch.is-checked .el-switch__core .el-switch__action {
    background-color: #fff !important;
  }

  .el-switch .el-switch__core .el-switch__inner .is-icon {
    color: #fff !important;
  }
  .el-switch.is-checked .el-switch__core .el-switch__inner .is-icon {
    color: #000 !important;
  }
  .mobile .el-switch.is-checked .el-switch__core .el-switch__inner {
    padding: 0 0px 0 21px !important;
  }
  .mobile .el-switch .el-switch__core .el-switch__inner {
    padding: 0 21px 0 1px !important;
  }
  .mobile .el-switch.is-checked .el-switch__core .el-switch__inner .is-icon {
    transform: rotate(-90deg);
  }

  .social-share .social-share-icon {
    width: 27px !important;
    height: 27px !important;
    border: none !important;
    background-size: cover !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
    transition: initial !important;
  }
  .social-share .icon-weibo:before {
    display: none !important;
  }
  .social-share .icon-wechat:before {
    display: none !important;
  }
  .social-share .icon-qq:before {
    display: none !important;
  }
  .social-share .icon-wechat {
    background-image: url(@/assets/images/btn-share-weixin-normal.png) !important;
    background-color: initial !important;
  }
  .social-share .icon-weibo {
    background-image: url(@/assets/images/btn-share-weibo-normal.png) !important;
    background-color: initial !important;
  }
  .social-share .icon-qq {
    background-image: url(@/assets/images/btn-share-qq-normal.png) !important;
    background-color: initial !important;
  }
  .social-share .icon-wechat:hover {
    background-image: url(@/assets/images/btn-share-weixin-active.png) !important;
    background-color: initial !important;
  }
  .social-share .icon-weibo:hover {
    background-image: url(@/assets/images/btn-share-weibo-active.png) !important;
    background-color: initial !important;
  }
  .social-share .icon-qq:hover {
    background-image: url(@/assets/images/btn-share-qq-active.png) !important;
    background-color: initial !important;
  }
}
</style>