<template>
  <div class="manufacture-page">
    <section class="banner"></section>

    <section class="section page-width">
      <h2 class="section-title">Smart Manufacturing Center</h2>

      <div class="center-swiper">
        <div @mouseenter="pauseAutoplay2" @mouseleave="resumeAutoplay2" style="max-width: 100%;">
          <Swiper @swiper="onSwiperInit2" :autoplay="{ delay: 350000, disableOnInteraction: false, pauseOnMouseEnter: false }" :loop="true" :modules="[SwiperAutoplay, SwiperEffectCreative, SwiperNavigation, SwiperPagination, SwiperController]" :slides-per-view="1" :space-between="0" :pagination="{ clickable: true }" navigation>
            <SwiperSlide v-for="(item, index) in manufactureCenterList2" :key="item.name" :virtualIndex="index">
              <img class="swiper-image" :src="item.image" alt="" />
            </SwiperSlide>
          </Swiper>
        </div>
      </div>
    </section>

    <section class="section page-width">
      <h2 class="section-title">{{ equipmentList.title }}</h2>

      <div class="equipment-grid">
        <div v-for="(item, index) in equipmentList.list" :key="index" class="equipment-item">
          <img :src="item.image" :alt="item.title" />
          <h3>{{ item.imageName }}</h3>
          <ul>
            <li v-for="(text, textIndex) in item.arr" :key="textIndex"><span>•</span> {{ text }}</li>
          </ul>
        </div>
      </div>
    </section>

    <section class="section page-width">
      <h2 class="section-title">Manufacturing Process</h2>

      <div class="process-box">
        <div class="process-image">
          <img :src="currentProcessImage" alt="Manufacturing Process" />
        </div>

        <div class="process-tabs">
          <button :class="{ active: processTabIndex === 0 }" @click="setProcessTab(0)">
            Active Component Production Process
          </button>
          <button :class="{ active: processTabIndex === 1 }" @click="setProcessTab(1)">
            Passive Component Production Process
          </button>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import zzlc from "@/assets/img/zzlc.png";
import finfo_2 from "@/assets/img/finfo_2.png";
import { useAll } from "~/api/pubAll/service";

type DatasType = any[][];

const props = defineProps<{
  datas: DatasType;
}>();

const processTabIndex = ref(0);
const packageTabIndex = ref(0);
const swiperInstance2 = ref<any>(null);

let manufactureCenterList2: any = ref([]);
const equipmentList: any = ref({});

const { getContent } = useAll();
const { data } = await useAsyncData("labPagedfdsf", () =>
  getContent({
    language: 2,
    code: 2,
  })
);

if (String(data.value?.httpCode) === "200") {
  equipmentList.value = data.value.data[2][0] || [];
  equipmentList.value.list.forEach((item: any) => {
    item.arr = item.remark.split(",");
  });
  manufactureCenterList2.value = data.value.data[1][0].list || [];
}

const currentProcessImage = computed(() => {
  if (processTabIndex.value === 1) {
    return zzlc;
  }
  return finfo_2;
});

const packageTitle = computed(() => {
  return props.datas?.[4]?.[0]?.title || "Package Types";
});

const packageContent = computed(() => {
  return props.datas?.[4]?.[0]?.content || "";
});

const packageList = computed(() => {
  const current = props.datas?.[4]?.[0];
  if (!current) {
    return [];
  }
  return packageTabIndex.value === 0 ? current.list1 || [] : current.list2 || [];
});

const setProcessTab = (index: number) => {
  processTabIndex.value = index;
};

const setPackageTab = (index: number) => {
  packageTabIndex.value = index;
};

const openOEM = () => {
  window.open("https://hm.baidu.com/hm.js?6fd5657038e12d87f6396d79d8c044bc", "", "height=600,width=800");
};

onMounted(() => {});
onBeforeUnmount(() => {});

const onSwiperInit2 = (swiper: any) => {
  swiperInstance2.value = swiper;
};

const pauseAutoplay2 = () => {
  if (swiperInstance2.value) {
    swiperInstance2.value.autoplay.stop();
  }
};

const resumeAutoplay2 = () => {
  if (swiperInstance2.value) {
    swiperInstance2.value.autoplay.start();
  }
};
</script>

<style scoped lang="scss">
.manufacture-page {
  background: #f5f5f5;
  color: #333333;
  padding-bottom: 1px;
}

.page-width {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 15px;
  box-sizing: border-box;
}

.banner {
  height: 200px;
  background-position: center;
  background-repeat: no-repeat;
  background: url(~/assets/img/banner/banner_pub.png) no-repeat center center;
  background-size: 100% auto;
}

.breadcrumb-wrap {
  padding: 16px 16px 0;
}

.section {
  padding: 32px 0;
}

.section-title {
  margin: 40px 0 15px;
  font-size: 18px;
  line-height: 32px;
  text-align: center;
  font-weight: 700;
}

.center-swiper {
  display: flex;
  justify-content: center;

  .swiper {
    width: 100%;
    height: 180px;
    border-radius: 12px;
    overflow: hidden;
  }
}

.swiper-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.equipment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;

  li {
    span {
      color: #000;
      font-weight: bold;
    }
  }
}

.equipment-item {
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  padding-bottom: 16px;
  text-align: center;

  img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
  }

  h3 {
    padding: 0 8px;
    font-size: 15px;
    line-height: 24px;
    font-weight: 700;
    margin: 20px 0 15px;
  }

  ul {
    padding: 0 12px;
    text-align: left;
    color: #666666;
    line-height: 22px;
    font-size: 12px;
  }
}

.process-box {
  padding: 16px;
  border: 1px solid #dddddd;
  border-radius: 12px;
  background: #ffffff;
  margin-bottom: 50px;
}

.process-image {
  text-align: center;

  img {
    width: 100%;
    display: inline-block;
  }
}

.process-tabs {
  display: flex;
  gap: 12px;
  margin-top: 16px;

  button {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid #d9001b;
    background: #ffffff;
    color: #d9001b;
    cursor: pointer;
    font-size: 12px;
  }

  .active {
    background: #d9001b;
    color: #ffffff;
  }
}

:deep(.swiper-button-next:after),
:deep(.swiper-button-prev:after) {
  font-size: 24px;
}

@media (min-width: 768px) {
  .page-width {
    max-width: 768px;
    padding: 0 15px;
  }

  .breadcrumb-wrap {
    padding: 16px 24px 0;
  }

  .center-swiper {
    .swiper {
      height: 220px;
    }
  }

  .equipment-item {
    img {
      height: 148px;
    }
  }
}
</style>
