<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_1.png" />
            </span>
          </template>
          <n-tab-pane
            name="exhibition"
            tab="展览"
            v-infinite-scroll="onLoadMore"
          >
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="3" class="tab-grid">
              <template v-for="(_, index) in 16">
                <n-gi>
                  <infoBox
                    :id="index + 1"
                    :title="`湘鄂赣省工农银行洋银叁角纸币-${index + 1}`"
                    cover="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
                    time="2023-01-02"
                  />
                </n-gi>
              </template>
            </n-grid>
          </n-tab-pane>
          <n-tab-pane name="activity" tab="活动">
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="3" class="tab-grid">
              <template v-for="(_, index) in 16">
                <n-gi>
                  <infoBox
                    :id="index + 1"
                    title="卡片"
                    cover="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
                    time="2023-01-02"
                  />
                </n-gi>
              </template>
            </n-grid>
          </n-tab-pane>
          <n-tab-pane name="news" tab="新闻">
            <n-grid :x-gap="XGap" :y-gap="YGap" :cols="3" class="tab-grid">
              <template v-for="item in news">
                <n-gi>
                  <info-box
                    :id="item.id"
                    :title="item.name"
                    :cover="domain + item.thumb"
                    :time="item.publishDate"
                  />
                </n-gi>
              </template>
            </n-grid>
          </n-tab-pane>
          <n-tab-pane name="notice" tab="通知">
            <n-grid :y-gap="YGap" :cols="1" class="tab-grid">
              <template v-for="(_, index) in 16">
                <n-gi>
                  <notice-box
                    :id="`${index + 2}_notice`"
                    title="这是一段标题这是一段标题"
                    content="这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段摘要这是一段..."
                    time="2023-01-02"
                  />
                </n-gi>
              </template>
            </n-grid>
          </n-tab-pane>
        </n-tabs>
      </div>
      <side-menu />
    </div>
  </div>
</template>

<script setup>
import { onMounted, watch, computed } from "vue";
import { vInfiniteScroll } from "@vueuse/components";
import infoBox from "../components/infoBox";
import subHeader from "../components/subHeader";
import sideMenu from "../components/sideMenu";
import noticeBox from "../components/noticeBox";
import { useInfoStore } from "../store/info";
const infoStore = useInfoStore();
const domain = ref(import.meta.env.VITE_DOMAIN_URL);
const currentTab = ref("exhibition");
const news = computed(() => infoStore.news);

const handleTabFetch = (type) => {
  switch (type) {
    case "exhibition":
      infoStore.getExhibition();
      break;
    case "activity":
      infoStore.getActivity();
      break;
    case "news":
      infoStore.getNews();
      break;
    case "notice":
      infoStore.getNotices();
      break;
  }
};

watch(
  currentTab,
  (val) => {
    console.log("currentTab", val);
    handleTabFetch(val);
  },
  {
    immediate: true,
  }
);
const XGap = ref(50);
const YGap = ref(50);

const onLoadMore = (type) => {
  // console.log("type", type);
  console.log("onLoadMore");
};
</script>

<style lang="scss" scoped></style>
