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

    <section class="section">
      <div class="container">
        <h2 class="title">{{ labTitle }}</h2>
        <p class="desc">{{ labDesc }}</p>
        <div class="device-grid">
          <div v-for="(item, index) in labList" :key="index" class="device-card">
            <img :src="item.image" />
            <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, index) in activeList" :key="index" class="device-card">
            <img :src="item.image" />
            <h3>{{ item.title }}</h3>
            <p>{{ item.content }}</p>
          </div>
        </div>
      </div>
    </section>

    <section class="section">
      <div class="container">
        <h2 class="title">{{ passiveTitle }}</h2>
        <p class="desc">{{ passiveDesc }}</p>

        <div class="device-grid">
          <div v-for="(item, index) in passiveList" :key="index" class="device-card">
            <img :src="item.image" />
            <h3>{{ item.title }}</h3>
            <p>{{ item.content }}</p>
          </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("labPage", () =>
  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] || {});

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 Testing Equipment"
);
const activeDesc = computed(() => activeSection.value?.content || "");
const activeList = computed(() => activeSection.value?.list || []);

const passiveTitle = computed(
  () => passiveSection.value?.title || "Passive Component Testing Equipment"
);
const passiveDesc = computed(() => passiveSection.value?.content || "");
const passiveList = computed(() => passiveSection.value?.list || []);
</script>

<style scoped lang="scss">
.lab-page {
  background: #f5f5f5;
}

.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 {
  background: #ffffff;
  padding: 16px 0;
}

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

.section {
  padding: 32px 0;
  background: #fff;
  margin-bottom: 12px;
}

.title {
  text-align: center;
  font-size: 18px;
  line-height: 32px;
  font-weight: bold;
}

.desc {
  margin-top: 12px;
  text-align: center;
  color: #666666;
  font-size: 14px;
  line-height: 24px;
}

.device-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.device-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.device-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
}

.device-card h3 {
  margin-top: 10px;
  font-size: 12px;
  line-height: 20px;
}

.device-card p {
  margin-top: 6px;
  font-size: 12px;
  line-height: 20px;
  color: #666666;
}

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

  .device-card img {
    height: 148px;
  }
}
</style>
