<template>
  <!-- 传播交流页 -->
  <div class=" main-background main-background-type0">
    <!-- 轮播 -->
    <Carousel v-bind="carouselConfig" class="main-header-box small carousel-light">
      <Slide class="main-header-box small">
        <img src="@/assets/images/fusion/Banner.jpg" />
      </Slide>
      <template #addons>
        <Navigation />
        <Pagination />
      </template>
    </Carousel>

    <!-- 闽南节庆日历 -->
    <section class="main-section pb-0">
      <div class="content">
        <div class="title">
          <h2>闽南节庆日历</h2>
        </div>
        <div class="calandar row">
          <div class="col col-12 col-lg-6 col-xl-6 p-0">
            <ScrollRect class="left-list">
              <h3 class="month-title">{{monthSelected}}月</h3>
              <NuxtLink 
                v-for="(item, index) in daysData"
                :key="index"
                :to="{ path: `/news/detail`, query: { id: item.id, modelId: 18 } }"
                class="link-wrapper"
              >
                <ImageTitleDescBlock
                  :title="item.title"
                  :image="item.image"
                  :desc="item.desc || item.title"
                />
              </NuxtLink>
            </ScrollRect>
          </div>
          <div class="month-grid col-12 col-lg-6 col-xl-6 p-0">
            <ScrollRect
              class="grid"
              v-for="(month, k) in monthData"
              :key="k"
              :class="[ monthSelected === month.month ? 'active' : '' ]"
              @click="monthChange(month.month)"
            >
              <h3>{{ month.month }}月</h3>
              <div class="tags">
                <span
                  v-for="(holiday, index) in month.holidays"
                  :key="index"
                >
                  {{ holiday.title }}
                </span>
              </div>
            </ScrollRect>
          </div>
        </div>
      </div>
    </section>

    <!-- 文旅融合 -->
    <section class="main-section">
      <div class="content">
        <div class="title">
          <h2>文旅融合</h2>
        </div>
        <ThreeImageList :list="list" />
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { Carousel, Slide, Pagination, Navigation } from 'vue3-carousel'
import { onMounted, ref, type Ref } from 'vue';
import Image1 from '@/assets/images/fusion/Image1.jpg'
import Image2 from '@/assets/images/fusion/Image2.jpg'
import Image3 from '@/assets/images/inheritor/Image3.jpg'
import Image4 from '@/assets/images/fusion/Image4.jpg'
import Image5 from '@/assets/images/fusion/Image5.jpg'
import Image6 from '@/assets/images/fusion/Image6.jpg'
import ImageTitleDescBlock from '@/components/parts/ImageTitleDescBlock.vue';
import ThreeImageList from '@/components/parts/ThreeImageList.vue';
import CalendarContent from '@/api/fusion/CalendarContent';
import { GetContentListItem, GetContentListParams } from '@/api/CommonContent';
import { ScrollRect } from '@imengyu/vue-scroll-rect';

const router = useRouter();
const carouselConfig = {
  itemsToShow: 1,
  wrapAround: true,
  autoPlay: 5000,
}
const list = [
  {
    title: '闽南文化景区',
    desc: '让文化因传承而永存',
    image: Image1,
    link: router.resolve('/fusion/scenic-spot').href,
  },
  {
    title: '文化旅游路线',
    desc: '让文化因传承而永存',
    image: Image2,
    link: router.resolve('/fusion/route').href,
  },
  {
    title: '非遗研学点',
    desc: '',
    image: Image6,
    link: router.resolve('/fusion/point').href,
  },
  {
    title: '非遗作品',
    desc: '让文化因传承而永存',
    image: Image3,
    link: router.resolve('/inheritor/products').href,
  },
  {
    title: '融合发展',
    desc: '非遗与旅游融合发展推荐目录',
    image: Image4,
    link: router.resolve('/fusion/demo-site').href,
  },
  {
    title: '闽南时尚',
    desc: '让文化因传承而永存',
    image: Image5,
    link: router.resolve('/fusion/fashion').href,
  },
]
const daysData = ref<GetContentListItem[]>([]) as Ref<GetContentListItem[]>
const monthSelected = ref(new Date().getMonth() + 1)
const { data: monthData } = await useAsyncData('funCalendarContent2', async () => {
  const res = await CalendarContent.getCalendarList(new GetContentListParams(), 1, 50)
  const year = new Date().getFullYear();

  const monthData : {
    month: number;
    holidays: GetContentListItem[];
  }[] = [
    {
      month: 1,
      holidays: []
    },
    {
      month: 2,
      holidays: []
    },
    {
      month: 3,
      holidays: []
    },
    {
      month: 4,
      holidays: []
    },
    {
      month: 5,
      holidays: []
    },
    {
      month: 6,
      holidays: []
    },
    {
      month: 7,
      holidays: []
    },
    {
      month: 8,
      holidays: []
    },
    {
      month: 9,
      holidays: []
    },
    {
      month: 10,
      holidays: []
    },
    {
      month: 11,
      holidays: []
    },
    {
      month: 12,
      holidays: []
    },
  ];

  res.list.filter(p => 
    p.dateYear === year
  ).forEach(item => {
    if (!item.desc)
      item.desc = item.title;
    item.title = item.title.substring(0, 10);
  });

  res.list.forEach(item => {
    monthData[item.dateMonth - 1]?.holidays?.push(item.toJSON() as any)
  })
  daysData.value = monthData[ monthSelected.value - 1].holidays as GetContentListItem[];
  return monthData;
})

function monthChange(month: number) {
  monthSelected.value = month;
  daysData.value = monthData.value?.[month - 1]?.holidays as GetContentListItem[] || [];
}
</script>

<style lang="scss">
@use '@/assets/scss/colors.scss' as *;

.calandar {
  background-color: $box-color;

  .left-list {
    height: 750px;
  }

  .link-wrapper {
    text-decoration: none;
    color: $text-color-light;
  }

  .month-title {
    margin: 24px 24px 0 24px;
  }
  .month-grid {
    display: grid;
    grid-template-columns: repeat(4, 25%);

    > .grid {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      background-color: $text-color-light;
      padding: 12px ;
      border: 1px solid $border-split-color;
      height: 250px;

      h3 {
        font-size: 18px;
      }
      .tags {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;

        > span {
          font-size: 13px;
          margin-right: 8px;
          margin-top: 8px;
          padding: 0 8px;
          border-radius: 12px;
          background-color: rgba(#FF961B, 0.1);

          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          overflow: hidden;
          text-overflow: ellipsis;
          word-break: break-all;
          line-height: 28px;
        }
      }

      &.active {
        background-color: $primary-color;
        color: $text-color-light;
      }
    }
  }
}


@media (max-width: 500px) {
  .calandar .month-grid {
    grid-template-columns: repeat(2, 50%);
  }
}
</style>

