<script setup lang="ts">
import { getStoreData } from '@/utils/composition';
import { traduction } from '@/utils/language';
import { reactive, toRefs, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { Resolution, useHome, WebStyleType } from '../../hooks/useHome';

const { getResolution, getWebStyle } = useHome();
const biosSupported = computed(() => getStoreData('loct', 'biosSupported'));
const resolution = getResolution;
const webStyle = getWebStyle();

const i18n = useI18n();
const props = defineProps({
  data: {
    type: Object,
    required: true,
    default: () => {
      return {};
    },
  },
});
const router = useRouter();
const { data } = toRefs(props);
let deviceData = data?.value?.data;
let productImg: '';
let hostName = deviceData?.ProductName;
let otherName = deviceData?.ProductAlias ? ` (${deviceData?.ProductAlias})` : null;
const productLabel = getStoreData('loct', 'sn');
const productinfoArr = [
  {
    id: 'productSN',
    label: traduction('HOME_PROJECTNO'),
    value: deviceData.ProductSN || '--',
  },
  {
    id: 'systemSN',
    label: traduction('INFO_SYSTEM_NUMBER'),
    value: deviceData.SystemSN || '--',
    hide: deviceData.ProductSN === deviceData.SystemSN,
  },
  {
    id: 'fqdn',
    label: traduction('HOME_HOST_NAME_DETAIL'),
    value: deviceData.FQDN || '--',
  },
  {
    id: 'ibmc',
    label: traduction('HOME_IBMC_VERSION', { softwareName: productLabel }),
    value: deviceData.BMCVersion || '--',
  },
  {
    id: 'bios',
    label: traduction('HOME_BIOS_VERSION'),
    value: deviceData.BIOSVersion || '--',
    hide: !biosSupported.value,
  },
  {
    id: 'tee',
    label: traduction('HOME_TEEOS_FIRMWARE_VERSION'),
    value: deviceData.TEEOSVersion || '--',
    hide: !biosSupported.value,
  },
  {
    id: 'mac',
    label: traduction('NET_MAC_ADDRESS'),
    value: deviceData.MAC || '--',
  },
  {
    id: 'flag',
    label: traduction('HOME_GUID_TAG'),
    value: deviceData.GUID,
  },
];
let serverDetail = reactive({
  serverType: null,
  serverType1: null,
  serverName: null,
  options: productinfoArr.filter((item: any) => item.hide !== true),
});

function navigatorToMore() {
  router.push({ path: '/navigate/system/info' });
}
</script>

<template>
  <div class="product-card">
    <div class="product-header">
      <span v-t="'HOME_DEVICEINFO'" class="title"></span>
      <span id="homeMoreLink" class="more-link" @click="navigatorToMore">查看更多</span>
    </div>
    <div class="product-content">
      <div class="product-details">
        <table class="product-table">
          <tr v-for="item in serverDetail.options" :key="item.id">
            <td class="detail-key">{{ item.label }}</td>
            <td class="detail-value">{{ item.value }}</td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.product-card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .product-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;

    .title {
      font-size: 16px;
      font-weight: bold;
      color: var(--o-text-color-primary);
    }

    .more-link {
      font-size: 12px;
      color: #1890ff;
      cursor: pointer;
      user-select: none;

      &:hover {
        color: #40a9ff;
        text-decoration: underline;
      }
    }
  }

  .product-content {
    display: flex;
    flex: 1;

    .product-details {
      width: 100%;

      .product-table {
        width: 100%;
        border-collapse: collapse;

        tr {
          border-bottom: 1px solid #eaeaea;

          &:last-child {
            border-bottom: none;
          }

          .detail-key {
            width: 40%;
            padding: 8px 6px;
            text-align: left;
            font-size: 12px;
            color: var(--o-text-color-secondary);
            vertical-align: top;
          }

          .detail-value {
            width: 60%;
            padding: 8px 6px;
            text-align: left;
            font-size: 13px;
            color: var(--o-text-color-primary);
            font-weight: 500;
          }
        }
      }
    }
  }
}
</style>
