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

const props = defineProps({
  data: {
    type: Array as PropType<ICpuTableRow[]>,
    required: true,
    default: () => {
      return {};
    },
  },
  num: {
    type: Number,
    required: true,
    default: 0,
  },
});

const { data, num } = toRefs(props);
const cpuDatas: ICpuTableRow[] = data?.value;
const tableId = 'cpuProcessorTable';
const showExtend = ref(false);

const cpuColumns: IColumn[] = [
  {
    title: 'COMMON_NAME',
    width: '7%',
    content: 'name',
  },
  {
    title: 'COMMON_MANUFACTURER',
    width: '13%',
    content: 'manufacturer',
  },
  {
    title: 'PROCESSOR_MODEL',
    width: '24%',
    content: 'model',
  },
  {
    title: 'FREQUECY_WITH_UNIT',
    width: '10%',
    content: 'frequency',
  },
  {
    title: 'CORE_THREADS_WITH_UNIT',
    width: '17%',
    content: 'totalCoresNum',
  },
  {
    title: 'CACHE_WITH_UNIT',
    width: '17%',
    content: 'cache',
  },
  {
    title: 'PROCESSOR_STATE',
    width: '10%',
    content: 'processorState',
  },
  {
    title: 'MEMORY_POSITION',
    width: '10%',
    content: 'position',
  },
];

const extendData = [
  {
    label: 'COMMON_NAME',
    content: 'name',
    hide: false,
  },
  {
    label: 'MEMORY_POSITION',
    content: 'position',
    hide: false,
  },
  {
    label: 'COMMON_MANUFACTURER',
    content: 'manufacturer',
    hide: false,
  },
  {
    label: 'PROCESSOR_MODEL',
    content: 'model',
    hide: false,
  },
  {
    label: 'PROCESSOR_ID',
    content: 'id',
    hide: false,
  },
  {
    label: 'PROCESSOR_FREQENCY',
    content: 'frequencyMHz',
    hide: false,
  },
  {
    label: 'PROCESSOR_CORECOUNT_THREADCOUNT',
    content: 'totalCores',
    hide: false,
  },
  {
    label: 'PROCESSOR_ENABLED_CORECOUNT_THREADCOUNT',
    content: 'totalEnabledCores',
    hide: false,
  },
  {
    label: 'PROCESSOR_FDM_ALARM_CACHE',
    content: 'cacheKiB',
    hide: false,
  },
  {
    label: 'PROCESSOR_STATE',
    content: 'processorState',
    hide: false,
  },
  {
    label: 'OTHER_PART_NUMBER',
    content: 'partNumber',
    hide: false,
  },
  {
    label: 'COMMON_SERIALNUMBER',
    content: 'serialNumber',
    hide: false,
  },
  {
    label: 'PROCESSOR_OTHER',
    content: 'otherParameters',
    hide: false,
  },
  {
    label: 'PROCESSOR_HBM_CAP',
    content: 'hbmCapacityMiB',
    hide: false,
  },
  {
    label: 'PROCESSOR_HBM_WIDTH',
    content: 'hbmWidthBits',
    hide: false,
  },
  {
    label: 'PROCESSOR_HBM_SPEED',
    content: 'hbmSpeedsMHz',
    hide: false,
  },
];

cpuDatas.forEach((cpu: ICpuTableRow) => {
  let showExtendData = JSON.parse(JSON.stringify(extendData));
  showExtend.value = true;
  showExtendData.forEach((element: any) => {
    element.hide = cpu[element.content] === undefined;
  });
  cpu.extendTitleArr = [
    {
      data: showExtendData,
    },
  ];
});
</script>

<template>
  <SystemInfoTable
    :id="tableId"
    :data="cpuDatas"
    :columns="cpuColumns"
    :showextend="showExtend"
    :num="num"
  />
</template>

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