<script setup lang="ts">
import type { NdmNvrDiagInfo, NdmNvrResultVO, Station } from '@/apis';
import { DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard, NvrDiskCard, NvrRecordCard } from '@/components';
import { isNvrCluster } from '@/helpers';
import destr from 'destr';
import { NFlex } from 'naive-ui';
import { computed, toRefs } from 'vue';

const props = defineProps<{
  ndmDevice: NdmNvrResultVO;
  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 NdmNvrDiagInfo;
});

const commonInfo = computed(() => {
  const { stCommonInfo } = lastDiagInfo.value ?? {};
  if (!stCommonInfo) return undefined;
  const { 设备ID, 软件版本, 生产厂商, 设备别名, 设备型号, 硬件版本 } = stCommonInfo;
  return {
    设备ID: 设备ID ?? '-',
    软件版本: 软件版本 ?? '-',
    生产厂商: 生产厂商 ?? '-',
    设备别名: 设备别名 ?? '-',
    设备型号: 设备型号 ?? '-',
    硬件版本: 硬件版本 ?? '-',
  };
});

const cpuUsage = computed(() => lastDiagInfo.value?.stCommonInfo?.CPU使用率);
const memUsage = computed(() => lastDiagInfo.value?.stCommonInfo?.内存使用率);

const diskHealth = computed(() => lastDiagInfo.value?.info?.diskHealth);
const diskArray = computed(() => lastDiagInfo.value?.info?.groupInfoList);
</script>

<template>
  <NFlex vertical>
    <DeviceHeaderCard :ndm-device="ndmDevice" :station="station" />
    <DeviceCommonCard :common-info="commonInfo" />
    <DeviceHardwareCard :cpu-usage="cpuUsage" :mem-usage="memUsage" />
    <NvrDiskCard :disk-health="diskHealth" :disk-array="diskArray" />
    <NvrRecordCard v-if="isNvrCluster(ndmDevice)" :ndm-device="ndmDevice" :station="station" />
  </NFlex>
</template>

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