<script setup lang="ts">
import InfoFormFiled from '@/pages/System/Info/components/product/InfoFormFiled.vue';
import { getProductInfo } from '../../service/system.service';
import { ref, computed } from 'vue';
import useStore from '@/stores';
import { ISystemInfo } from '../../product.datatype';
import { getProductData, getOSData, getDigitalWarrantyData } from '../../utils/system.util';
import { getStoreData, loading } from '@/utils/composition';

loading(true);
const systemInfoArray = ref([] as ISystemInfo[]);
const store = useStore();
const boardName = getStoreData('glob', 'boardName');
// 使用 computed 响应式读取 store 数据，确保异步初始化后能触发重新渲染
const ibmaspt = computed(() => getStoreData('loct', 'ibmaspt'));
const biosSupported = computed(() => getStoreData('loct', 'biosSupported'));

getProductInfo()
  .then((res: any) => {
    const systemData = res.data;
    // 产品信息
    if (systemData.Product) {
      systemInfoArray.value.push(getProductData(systemData.Product, store, { biosSupported: biosSupported.value }));
    }
    // 软件信息
    if (ibmaspt.value) {
      if (systemData.OS && systemData.OS.BMARunningStatus === 'Running') {
        systemInfoArray.value.push(getOSData(systemData.OS));
      } else {
        systemInfoArray.value.push({
          title: 'INFO_SYSTEM',
          backgroundClassName: 'os-img',
          id: 'systemInfo',
          data: [],
        });
      }
    }

    // 电子保单,服务年限不是有效值时隐藏“电子保单”标签
    if (
      systemData.DigitalWarranty &&
      systemData.DigitalWarranty.Lifespan !== null &&
      systemData.DigitalWarranty.Lifespan !== undefined
    ) {
      systemInfoArray.value.push(getDigitalWarrantyData(systemData.DigitalWarranty, store));
    }
    loading(false);
  })
  .catch(() => {
    loading(false);
  });
</script>

<template>
  <div id="infoProduct">
    <InfoFormFiled v-for="item in systemInfoArray" :key="item.title" :data="item" />
  </div>
</template>

<style lang="scss" scoped></style>
