<script setup lang="ts">
import SystemInfoTable from '../SystemInfoTable/SystemInfoTable.vue';
import type { PropType } from 'vue';
import { toRefs, ref } from 'vue';
import { INpuTableRow } from '../../product.datatype';

const props = defineProps({
  data: {
    type: Array as PropType<INpuTableRow[]>,
    required: true,
    default: () => {
      return {};
    },
  },
  num: {
    type: Number,
    required: true,
    default: 0,
  },
});
const { data, num } = toRefs(props);
const npuDatas: INpuTableRow[] = data?.value;
const tableId = 'npuProcessorTable';
const showExtend = ref(false);

const npuColumns = [
  {
    title: 'COMMON_NAME',
    content: 'name',
    width: '10%',
  },
  {
    title: 'COMMON_MANUFACTURER',
    content: 'manufacturer',
    width: '15%',
  },
  {
    title: 'PROCESSOR_MODEL',
    content: 'model',
    width: '20%',
  },
  {
    title: 'IRM_POWER',
    content: 'powerWatts',
    width: '17%',
  },
  {
    title: 'COMMON_FIXED_VERSION',
    content: 'firmwareVersion',
    width: '18%',
  },
  {
    title: 'PROCESSOR_DIE_ID',
    content: 'serialNumber',
    width: '20%',
  },
];

npuDatas.forEach((npu: INpuTableRow) => {
  showExtend.value = true;
  npu.extendTitleArr = [
    {
      data: [
        {
          label: 'COMMON_NAME',
          content: 'name',
          hide: npu.name === undefined,
        },
        {
          label: 'COMMON_MANUFACTURER',
          content: 'manufacturer',
          hide: npu.manufacturer === undefined,
        },
        {
          label: 'PROCESSOR_MODEL',
          content: 'model',
          hide: npu.model === undefined,
        },
        {
          label: 'IRM_POWER',
          content: 'powerWatts',
          hide: npu.powerWatts === undefined,
        },
        {
          label: 'COMMON_FIXED_VERSION',
          content: 'firmwareVersion',
          hide: npu.firmwareVersion === undefined,
        },
        {
          label: 'PROCESSOR_DIE_ID',
          content: 'serialNumber',
          hide: npu.serialNumber === undefined,
        },
        {
          label: 'ALARM_REPORT_EMAIL_SUBJECT_1',
          content: 'boardSerialNumber',
          hide: npu.boardSerialNumber === undefined,
        },
      ],
    },
  ];
});
</script>

<template>
  <SystemInfoTable
    :id="tableId"
    :data="npuDatas"
    :columns="npuColumns"
    :showextend="showExtend"
    :num="num"
  />
</template>

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