<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">
            <h3 class="month-title">1月</h3>
            <ImageTitleDescBlock
              v-for="(item, index) in daysData"
              :key="index"
              :title="item.title"
              :image="item.image"
              :desc="item.desc || item.title"
              @click="goDetail(item.id)"
            />
          </div>
          <div class="month-grid col-12 col-lg-6 col-xl-6 p-0">
            <div 
              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>
            </div>
          </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/fusion/Image3.jpg'
import Image4 from '@/assets/images/fusion/Image4.jpg'
import Image5 from '@/assets/images/fusion/Image5.jpg'
import LeftRightBox from '@/components/parts/LeftRightBox.vue';
import ImageTitleDescBlock from '@/components/parts/ImageTitleDescBlock.vue';
import ThreeImageList from '@/components/parts/ThreeImageList.vue';
import { usePageAction } from '@/composeable/PageAction';
import CommonContent, { GetContentListItem, GetContentListParams } from '@/api/CommonContent';

const carouselConfig = {
  itemsToShow: 1,
  wrapAround: true,
  autoPlay: 5000,
}
const list = [
  {
    title: '闽南文化景区',
    desc: '让文化因传承而永存',
    image: Image1,
    onClick: () => {
      navTo('/fusion/scenic-spot');
    }
  },
  {
    title: '文化旅游路线',
    desc: '让文化因传承而永存',
    image: Image2,
    onClick: () => {
      navTo('/fusion/route');
    }
  },
  {
    title: '文化产品',
    desc: '让文化因传承而永存',
    image: Image3,
    onClick: () => {
      navTo('/fusion/products');
    }
  },
  {
    title: '文旅融合示范点',
    desc: '让文化因传承而永存',
    image: Image4,
    onClick: () => {
      navTo('/fusion/demo-site');
    }
  },
  {
    title: '闽南时尚',
    desc: '让文化因传承而永存',
    image: Image5,
    onClick: () => {
      navTo('/fusion/fashion');
    }
  },
  {
    title: '',
    desc: '',
    image: '',
  }
]
const daysData = ref<GetContentListItem[]>([]) as Ref<GetContentListItem[]>
const monthSelected = ref(1)
const monthData = ref<{
  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: []
  },
])

onMounted(async () => {
  const res = await CommonContent.getContentList(new GetContentListParams()
    .setModelId(18)
    .setMainBodyColumnId(272)
  , 1, 50)

  res.list.forEach(item => {
    item.month = Math.floor(Math.random() * 12 + 1);
    if (!item.desc)
      item.desc = item.title;
    item.title = item.title.substring(0, 10);
  });

  res.list.forEach(item => {
    monthData.value[item.month as number - 1].holidays.push(item)
  })

  daysData.value = monthData.value[0].holidays as GetContentListItem[];
});

function goDetail(id: number) {
  navTo(`/news/detail`, { id, modelId: 18 });
}
function monthChange(month: number) {
  monthSelected.value = month;
  daysData.value = monthData.value[month - 1].holidays as GetContentListItem[];
}

const { navTo } = usePageAction();

</script>

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

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

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

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

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

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

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


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

