<template>
  <div
    class="relic-detail"
    :class="{
      isDarkTheme,
      notDarkTheme: !isDarkTheme,
    }"
  >
    <el-switch
      :model-value="isDarkTheme"
      class="theme-switch"
      inline-prompt
      :active-icon="Moon"
      :inactive-icon="Sunny"
      @update:modelValue="onThemeChange"
    />
    <article
      class="desc"
      :class="{
        isDarkTheme,
        notDarkTheme: !isDarkTheme,
      }"
    >
      <h1 v-html="$gConfigInfo.objInfo[$route.query.m]" />
      <div
        v-show="isShowDescDetail"
        class="splitter"
      />
      <div
        v-show="isShowDescDetail"
        class="detail"
        v-html="$gConfigTxt.txtObj[$route.query.m]"
      />
    </article>
    <!-- 假的阴影 -->
    <!-- <img
      class="relic-shadow"
      src="@/assets/images/relic-shadow.png"
      alt=""
      draggable="false"
    > -->

    <transition name="fade-out">
      <img
        v-if="isShowLogo"
        :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
        class="show-detail"
        @click="onClickShowDetail"
      >
        <img
          :src="require(`@/assets/images/btn-desc-${isDarkTheme ? 'dark' : 'light'}${isShowDescDetail ? '-active' : ''}.png`)"
          alt=""
          draggable="false"
        >
      </button>
      <button
        class="show-help"
        @click="onClickShowHelp"
      >
        <img
          :src="require(`@/assets/images/btn-help-${isDarkTheme ? 'dark' : 'light'}${isShowHelp ? '-active' : ''}.png`)"
          alt=""
          draggable="false"
        >
      </button>
      <button class="share">
        <img
          :src="require(`@/assets/images/btn-share-${isDarkTheme ? 'dark' : 'light'}.png`)"
          alt=""
          draggable="false"
        >
      </button>
    </menu>

    <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,
    }
  },
  computed: {
    ...mapState([
      'isDarkTheme',
    ]),
    Sunny() {
      return Sunny
    },
    Moon() {
      return Moon
    },
  },
  created() {
    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)
  },
  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
    }
  }
}
</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:10px;
    right: 10px;
    z-index: 1;
  }
  > article.desc {
    position: absolute;
    top: 127px;
    left: 110px;
    width: 503px;
    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%;
      }
    }
  }
  ::-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>