<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.img" alt="" />
            </SwiperSlide>
          </Swiper>
        </div>
      </div>
    </section>

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

      <div class="equipment-grid">
        <div v-for="(item, index) in equipmentList" :key="index" class="equipment-item">
          <img :src="item.img" :alt="item.title" />
          <h3>{{ item.title }}</h3>
          <ul>
            <li v-for="(text, textIndex) in item.text" :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 sb1 from "@/assets/img/sb_1.png";
import sb2 from "@/assets/img/sb_2.png";
import sb3 from "@/assets/img/sb_3.png";
import sb4 from "@/assets/img/sb_4.png";
import sb5 from "@/assets/img/sb_5.png";
import zzlc from "@/assets/img/zzlc.png";
import finfo_2 from "@/assets/img/finfo_2.png";

type DatasType = any[][];

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

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

const bannerStyle = computed(() => ({
  backgroundImage: `url(https://doc.hotking.com/hkt/adpos/pic/%E5%B0%81%E6%B5%8B%E4%BB%A3%E5%B7%A5-%E4%B8%AD%20%283%29.png)`,
}));

const manufactureCenterList2 = ref([
  {
    name: "HKT South China Manufacturing Base",
    img: "http://doc.hotking.com/hkt/adpos/pic/%E5%9B%9B%E5%B7%9Dfinfo.png",
  },
  {
    name: "HKT Southwest Manufacturing Base",
    img: "http://doc.hotking.com/hkt/adpos/pic/%E5%9B%9B%E5%B7%9Dfinfo.png",
  },
]);

const equipmentTitle = computed(() => {
  return props.datas?.[2]?.[0]?.title || "Advanced Equipment";
});

const equipmentList = ref([
  {
    title: "Die Bonding Workshop",
    img: sb1,
    text: ["ASMLotus-E", "ASM838", "ASM830", "LDAB", "ASMLotus-R", "XZD SMA/SMAFL", "ASM830Plus"],
  },
  {
    title: "Wire Bonding Workshop",
    img: sb2,
    text: ["ASM iHAWK Xtreme", "ASM iHAWK Xtreme GOCU", "XZD SMA/SMAFL", "ASM838"],
  },
  {
    title: "Molding Workshop",
    img: sb3,
    text: [
      "SOT-23 Molding Mold",
      "ESOP-8/10 Molding Mold",
      "SOT-89 Molding Mold",
      "SOP-7/8/10 Molding Mold",
      "SOT-23-6/5/3 Molding Mold",
      "SOD-123 Molding Mold",
      "SOD-123FL Molding Mold",
      "SMA Molding Mold",
      "SMB Molding Mold",
      "MBF Molding Mold",
    ],
  },
  {
    title: "Forming Workshop",
    img: sb4,
    text: [
      "ASM Forming Machine",
      "CORBEST Forming Mold",
      "ASM Forming Mold",
      "HL Forming Mold",
      "HL Forming Machine",
      "YSH Forming Mold",
      "CORBEST Forming Machine",
      "SANJIA YAMADA Forming Machine",
      "SANJIA YAMADA Forming Mold",
    ],
  },
  {
    title: "Testing Workshop",
    img: sb5,
    text: ["ASM FT2018", "FUDE FD1640", "JCTS-200S", "QT-4100A", "TR6850S", "AZUR Xi805", "DTS-1000", "Existech 200", "TRIPOD", "ES-700DSWH", "SD-DVFT-600B"],
  },
]);

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: 14px;
  }

  .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>
