<script setup lang="ts">
import RightTabs from '@/components/RightTabs/RightTabs.vue';
import { getStoreData } from '@/utils/composition';
import { useRouter } from 'vue-router';
import { getCPUData } from '@/services/system/bios-service';
import { ref, onMounted } from 'vue';

const router = useRouter();
const route = router.currentRoute.value.fullPath;
let currentIdx = ref(route.indexOf('cpu') > -1 ? '1' : '0');
const armSupport = getStoreData('loct', 'armspt');
const cpuSupport = getStoreData('loct', 'cpuspt');

// Tabs
const tabList = [
  {
    id: 'biosTab',
    index: '0',
    label: 'BIOS_BOOT_DEVICE',
    name: 'bios',
    router: '/navigate/system/bios-settings/bios',
  },
  {
    id: 'cpuTab',
    index: '1',
    label: 'BIOS_CPU_ADJUSTMENT',
    name: 'cpu',
    router: '/navigate/system/bios-settings/cpu',
  },
  {
    id: 'biosSettingTab',
    index: '2',
    label: 'BIOS_CONFIG_MENU',
    name: 'cpu',
    router: '/navigate/system/bios-settings/setting',
  },
  {
    id: 'biosConfigExportTab',
    index: '3',
    label: 'BIOS_CONFIG_EXPORT',
    name: 'export',
    router: '/navigate/system/bios-settings/export',
  },
];

const currentTabItem = tabList.find(item => {
  return item.router === route;
});
if (currentTabItem) {
  currentIdx.value = currentTabItem.index;
}

// Arm架构不支持CPU操作，不显示CPU页面
if (armSupport || !cpuSupport) {
  tabList.splice(1, 1);
}

const handleSelect = (key: any) => {
  let res = tabList.find(item => {
    return item.index === key;
  });
  if (res) {
    router.push(res.router);
  }
};

onMounted(() => {
  router.push(tabList[0].router);
});
</script>

<template>
  <div class="root-container">
    <div class="bios-config">
      <RightTabs :check-tab-index="currentIdx" :tab-list="tabList" :is-route-mode="true" @handle-select="handleSelect" />
      <router-view @handle-change="handleSelect" />
    </div>
  </div>
</template>

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