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

    <!-- content -->
    <section class="section" v-for="(section, index) in sections" :key="index">
      <div v-if="section" class="container">
        <h2 class="title">{{ section.content || getSectionTitle(index) }}</h2>

        <div v-if="section.list?.length" class="device-grid">
          <div v-for="(item, itemIndex) in section.list" :key="itemIndex" class="device-card">
            <img class="device-image" :src="item.image" :alt="item.title || ''" />
            <h3>{{ item.title }}</h3>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

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

interface CertItem {
  image?: string;
  title?: string;
}

interface SectionItem {
  content?: string;
  list?: CertItem[];
}

const { getContent } = useAll();

const { data: pageData } = await useAsyncData("patentPagezzlssadas", () =>
  getContent({
    language: 2,
    code: 7,
  })
);

const rawData = computed<any[][]>(() => {
  return Array.isArray(pageData.value?.data) ? pageData.value?.data : [];
});

const headerData = computed(() => rawData.value?.[0]?.[0] || {});

const sections = computed<SectionItem[]>(() => {
  return rawData.value
    .slice(1)
    .map((item) => item?.[0])
    .filter(Boolean);
});

const bannerImage = computed(() => {
  return headerData.value?.list?.[0]?.image || "";
});

const bannerStyle = computed(() => ({
  backgroundImage: bannerImage.value ? `url(${bannerImage.value})` : "",
}));

const getSectionTitle = (index: number) => {
  const titleMap = [
    "Quality System Certification",
    "Environmental Certificates",
    "Patent Certificates",
  ];
  return titleMap[index] || "Certificate Showcase";
};

useHead({
  title: "Qualifications & Patents - Shenzhen HKT Electronics Co., Ltd.",
  meta: [
    {
      name: "description",
      content:
        "HKT holds a range of qualifications and patents, including ISO9001, ISO14001, IATF 16949, quality system certifications, EU ROHS certification, and multiple R&D patents.",
    },
    {
      name: "keywords",
      content:
        "qualifications, patents, quality system certification, environmental certificates, patent certificates",
    },
  ],
});
</script>

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

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

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

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

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

.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;
  border: 1px solid #ededed;
}

.device-image {
  width: 100%;
  height: 160px;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
}

.device-card h3 {
  margin-top: 10px;
  font-size: 12px;
  line-height: 20px;
  color: #ffffff;
  background: #ff4b4b;
  border-radius: 8px;
  padding: 8px 6px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

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

  .device-image {
    height: 220px;
  }
}
</style>
