<script setup lang="ts">
import type { NdmSwitchDiagInfo, NdmSwitchResultVO, Station } from '@/apis';
import { DeviceHardwareCard, DeviceHeaderCard, SwitchPortCard } from '@/components';
import destr from 'destr';
import { NFlex } from 'naive-ui';
import { computed, toRefs } from 'vue';

const props = defineProps<{
  ndmDevice: NdmSwitchResultVO;
  station: Station;
}>();

const { ndmDevice, station } = toRefs(props);

const lastDiagInfo = computed(() => {
  const result = destr<any>(ndmDevice.value.lastDiagInfo);
  if (!result) return null;
  if (typeof result !== 'object') return null;
  return result as NdmSwitchDiagInfo;
});

const cpuUsage = computed(() => lastDiagInfo.value?.cpuRatio);
const memUsage = computed(() => lastDiagInfo.value?.memoryRatio);

const ports = computed(() => lastDiagInfo.value?.info?.portInfoList);
</script>

<template>
  <NFlex vertical>
    <DeviceHeaderCard :ndm-device="ndmDevice" :station="station" />
    <DeviceHardwareCard :cpu-usage="cpuUsage" :mem-usage="memUsage" />
    <SwitchPortCard :ndm-device="ndmDevice" :station="station" :ports="ports" />
  </NFlex>
</template>

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