<template>
  <div class="main">
    <div class="content">
      <sub-header />
      <hero-sub-title :type="2" />
      <div class="left">
        <div class="container">
          <div class="top_banner">
            <div class="go-back">
              <img :src="exBack" @click="$router.go(-1)" />
            </div>
            <div class="vr-btn-container" v-if="detail.link">
              <img :src="vrBtn" @click="handleVRButton(detail.link)" />
            </div>
          </div>

          <div class="info">
            <div class="show-case"></div>
            <!-- {{ detail }} -->
            <h3 class="title">{{ detail.name }}</h3>
            <div class="label-container">
              <div class="label-list">
                <span v-if="detail.address">{{ detail.address }}</span>
                <span v-if="detail.type">{{ typeLabel(detail.type) }}</span>
                <span v-if="detail.publishDate">{{ detail.publishDate }}</span>
              </div>
            </div>
            <div class="text" v-html="detail.richText"></div>
          </div>
        </div>
      </div>
      <side-menu />
    </div>
  </div>
</template>

<script setup>
import { watchEffect, computed, unref, onMounted } from "vue";
import heroSubTitle from "../components/heroSubTitle";
import subHeader from "../components/subHeader";
import sideMenu from "../components/sideMenu";
import exBack from "../assets/ex_back.png";
import vrBtn from "../assets/vr_button.png";
import { useRouter } from "vue-router";
import { useExhibitionStore } from "../store/exhibition";
const exhibitionStore = useExhibitionStore();
const router = useRouter();
const detail = computed(() => exhibitionStore.detail);
// const domain = ref(import.meta.env.VITE_DOMAIN_URL);

const topBannerUrl = computed(() =>
  detail.value.thumb
    ? `url(${import.meta.env.VITE_DOMAIN_URL + detail.value.thumb})`
    : ""
);

const typeLabel = computed(() => (type) => {
  switch (type) {
    case "long":
      return "常设展览";
    case "topic":
      return "专题展览";
    case "temp":
      return "临时展览";
  }
});

const handleVRButton = (id) => {
  // const url = `https://sit-qiushoubwg.4dage.com/scene/index.html#/?m=1196`;
  console.log("VR-scene", id);
  if (id) {
    router.push(`/model-viewer/${id}`);
  }
};
const props = defineProps({
  id: {
    type: [String, Number],
    default: () => null,
    required: true,
  },
});
onMounted(() => {
  if (props.id) {
    exhibitionStore.getDetail(props.id);
  }
});

watchEffect(() => {
  if (unref(detail)) {
    document.title = unref(detail).name;
  }
});
</script>

<style>
.main {
  --main-ex-top-banner: v-bind(topBannerUrl);
}
</style>

<style lang="scss" scoped>
.container {
  flex: 1;
  overflow-y: scroll;
  padding-bottom: 200px;
  &::-webkit-scrollbar {
    display: none;
  }
}
.top_banner {
  width: 100%;
  background-image: var(--main-ex-top-banner);
  height: 29.375rem;
  background-position: top center;
  background-size: cover;
  position: relative;
  .go-back {
    display: inline-flex;
    position: absolute;
    top: 1.25rem;
    left: 0;
    width: 100%;
    height: 1.75rem;
    justify-content: flex-start;
    padding: 0 1.25rem;
    img {
      height: 100%;
      cursor: pointer;
    }
  }
  .vr-btn-container {
    display: inline-flex;
    position: absolute;
    bottom: 1.25rem;
    left: 0;
    width: 100%;
    height: 1.875rem;
    justify-content: center;
    img {
      height: 100%;
      cursor: pointer;
    }
  }
}

.info {
  max-width: 66.8125rem;
  margin: 0 auto;
  font-size: 20px;
  .title {
    font-size: 1.875rem;
    line-height: 3.75rem;
    margin: 1.2rem 0;
    text-align: center;
  }
  .label-container {
    display: flex;
    justify-content: center;
  }
  .label-list {
    margin: 1.5rem auto;
    // margin-bottom: ;
    display: inline-flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 0 1.875rem;

    span {
      padding-left: 1.5625rem;
      background-image: url("/img/dot.png");
      background-repeat: no-repeat;
      background-size: 1.25rem 1.25rem;
      background-position: left center;
    }
  }
  .text {
    font-weight: 400;
    color: #6e6e6e;
    line-height: 2.125rem;
    font-size: 1.25rem;
  }
}
</style>
