<template>
  <div class="lab-page">
    <!-- banner -->
    <section class="banner" :style="bannerStyle">
    </section>

    <!-- 面包屑 -->
    <div class="breadcrumb-wrap">
      <div class="breadcrumb">
        Current Location: <NuxtLink to="/">Manufacturing</NuxtLink>&nbsp;>&nbsp;Laboratory Center
      </div>
    </div>
    <!-- 工程实验室 -->
    <section class="section">
      <div class="container">
        <h2 class="title">{{ labTitle }}</h2>
        <p class="desc">{{ labDesc }}</p>
        <div class="device-grid">
          <div v-for="(item, i) in labList" :key="i" class="device-card">
            <div class="img-wrap">
              <img :src="item.image" />
            </div>
            <h3>{{ item.title }}</h3>
          </div>
        </div>
      </div>
    </section>

    <!-- 主动器件检测设备 -->
    <section class="section">
      <div class="container">
        <h2 class="title">{{ activeTitle }}</h2>
        <p class="desc">{{ activeDesc }}</p>

        <div class="device-grid">
          <div v-for="(item, i) in activeList" :key="i" class="device-card">
            <div class="img-wrap">
              <img :src="item.image" />
            </div>
            <h3>{{ item.title }}</h3>
          </div>
        </div>
      </div>
    </section>

    <!-- 被动器件检测设备 -->
    <section class="section" v-if="false">
      <div class="container">
        <h2 class="title">{{ passiveTitle }}</h2>
        <p class="desc">{{ passiveDesc }}</p>

        <div class="device-grid">
          <div v-for="(item, i) in passiveList" :key="i" class="device-card">
            <div class="img-wrap">
              <img :src="item.image" />
            </div>
            <h3>{{ item.title }}</h3>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";
import { useAll } from "~/api/pubAll/service";

const { getContent } = useAll();

const pageData = ref<any[]>([]);

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

if (String(data.value?.httpCode) === "200") {
  pageData.value = data.value.data || [];
}

/**
 * 数据结构（你要按实际接口调）
 */
const bannerSection = computed(() => pageData.value?.[0]?.[0] || {});
const labSection = computed(() => pageData.value?.[1]?.[0] || {});
const activeSection = computed(() => pageData.value?.[2]?.[0] || {});
const passiveSection = computed(() => pageData.value?.[3]?.[0] || {});

/** banner */
const bannerTitle = computed(() => bannerSection.value?.title || "Automotive-Grade Production Line");
const bannerDesc1 = computed(() => bannerSection.value?.remark || "");
const bannerDesc2 = computed(() => bannerSection.value?.desc || "");
const bannerStyle = computed(() => ({
  backgroundImage: `url(${
    bannerSection.value?.image || bannerSection.value?.list?.[0]?.image
  })`,
}));

/** 工程实验室 */
const labTitle = computed(() => labSection.value?.title || "Engineering Laboratory");
const labDesc = computed(() => labSection.value?.content || "");
const labList = computed(() => labSection.value?.list || []);

/** 主动设备 */
const activeTitle = computed(
  () => activeSection.value?.title || "Active Component Test Equipment"
);
const activeDesc = computed(() => activeSection.value?.content || "");
const activeList = computed(() => activeSection.value?.list || []);

/** 被动设备 */
const passiveTitle = computed(
  () => passiveSection.value?.title || "Passive Component Test Equipment"
);
const passiveDesc = computed(() => passiveSection.value?.content || "");
const passiveList = computed(() => passiveSection.value?.list || []);
</script>

<style scoped lang="scss">
.lab-page {
  background: #f5f5f5;
}
.container {
  max-width: 1600px;
  width: 90%;
  margin: 0 auto;
  padding: 0 20px;
}
/* banner */
.banner {
  height: 350px;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-size: auto 350px;
}
.breadcrumb-wrap {
  background: #fff;
  padding: 18px 0;
}
.banner-mask {
  height: 100%;
  background: rgba(214, 0, 28, 0.5);
}
.banner-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: #fff;
}
.banner-content h1 {
  font-size: 56px;
}
.banner-content p {
  font-size: 22px;
}
.section {
  padding: 100px 0;
}
.title {
  text-align: center;
  font-size: 32px;
  font-weight: bold;
}
.desc {
  text-align: center;
  margin-top: 15px;
  color: #666;
}

/* 实验室 */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-top: 30px;
}
.lab-item {
  position: relative;
}
.lab-item img {
  width: 100%;
}
.lab-tag {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: rgba(214, 0, 28, 0.7);
  color: #fff;
  text-align: center;
  padding: 10px 0;
}

/* 设备列表（关键：不轮播） */
.device-grid {
  margin-top: 40px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
}
@media (max-width: 1280px) {
  .device-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.device-card {
  background: #fff;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .img-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.device-card img {
  width: 100%;
  height: max-content;
  object-fit: cover;
}
.device-card h3 {
  margin-top: 10px;
  font-size: 14px;
}
.device-card p {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
}
</style>
