<template>
  <div class="main">
    <div class="content">
      <sub-header />
      <div class="left">
        <n-tabs type="line" pane-class="tab-content" v-model:value="currentTab">
          <template #prefix>
            <span class="meta-title">
              <img src="@/assets/subtitle_2.png" />
            </span>
          </template>
          <n-tab-pane name="all" tab="全部展览" v-infinite-scroll="onLoadMore">
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="1" class="tab-grid">
              <template v-for="item in exhibitionList">
                <n-gi>
                  <!-- {{ item }} -->
                  <exhibition-box
                    :id="item.id"
                    :title="item.name"
                    :cover="domain + item.thumb"
                    :content="item.richText"
                    :location="item.address"
                    :type="item.type"
                    isHasVR
                  />
                </n-gi>
              </template>
            </n-grid>
            <empty :show="exhibitionList.length === 0" :height="500" />
          </n-tab-pane>
          <n-tab-pane name="long" tab="常设展览" v-infinite-scroll="onLoadMore">
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="1" class="tab-grid">
              <template v-for="item in exhibitionList">
                <n-gi>
                  <exhibition-box
                    :id="item.id"
                    :title="item.name"
                    :cover="domain + item.thumb"
                    :content="item.richText"
                    :location="item.address"
                    :type="item.type"
                    :isHasVR="item.link.length > 0"
                  />
                </n-gi>
              </template>
            </n-grid>
            <empty :show="exhibitionList.length === 0" :height="500" />
          </n-tab-pane>
          <n-tab-pane
            name="topic"
            tab="专题展览"
            v-infinite-scroll="onLoadMore"
          >
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="1" class="tab-grid">
              <template v-for="item in exhibitionList">
                <n-gi>
                  <exhibition-box
                    :id="item.id"
                    :title="item.name"
                    :cover="domain + item.thumb"
                    :content="item.richText"
                    :location="item.address"
                    :type="item.type"
                    :isHasVR="item.link.length > 0"
                  />
                </n-gi>
              </template>
            </n-grid>
            <empty :show="exhibitionList.length === 0" :height="500" />
          </n-tab-pane>
          <n-tab-pane name="temp" tab="临时展览" v-infinite-scroll="onLoadMore">
            <n-grid :y-gap="YGap" :cols="1" class="tab-grid">
              <template v-for="item in exhibitionList">
                <n-gi>
                  <exhibition-box
                    :id="item.id"
                    :title="item.name"
                    :cover="domain + item.thumb"
                    :content="item.richText"
                    :location="item.address"
                    :type="item.type"
                    :isHasVR="item.link.length > 0"
                  />
                </n-gi>
              </template>
            </n-grid>
            <empty :show="exhibitionList.length === 0" :height="500" />
          </n-tab-pane>
        </n-tabs>
      </div>
      <side-menu />
    </div>
  </div>
</template>

<script setup>
import { computed, watch } from "vue";
import { vInfiniteScroll } from "@vueuse/components";
import { useThrottleFn } from "@vueuse/core";
import subHeader from "../components/subHeader";
import sideMenu from "../components/sideMenu";
import exhibitionBox from "../components/exhibitionBox";
import { useExhibitionStore } from "../store/exhibition";
import empty from "../components/empty.vue";

const loadingBar = useLoadingBar();
const exhibitionStore = useExhibitionStore();
const domain = ref(import.meta.env.VITE_DOMAIN_URL);
const exhibitionList = computed(() => exhibitionStore.lists);

const XGap = ref(50);
const YGap = ref(50);

const currentTab = ref("all");

watch(
  currentTab,
  async (val) => {
    console.log("val", val);
    loadingBar.start();
    await exhibitionStore.getExhibitionList(1, val);
    loadingBar.finish();
  },
  {
    immediate: true,
  }
);
const onLoadMore = useThrottleFn(async () => {
  if (exhibitionStore.isLoad) {
    console.log("canLoadMore", exhibitionStore.canLoadMore);
    exhibitionStore.canLoadMore && loadingBar.start();
    await exhibitionStore.loadMore(currentTab.value);
    loadingBar.finish();
  }
}, 1000);
</script>

<style lang="scss" scoped>
:deep(.n-tabs) {
  --n-tab-font-size: 1.25rem;
  --n-tab-gap: 60px;
  height: 100%;
  overflow: hidden;
  .n-tab-pane {
    overflow-y: scroll;
  }
  .n-tabs-bar {
    height: 0.25rem;
    border-radius: 1.875rem !important;
  }
}
</style>
