<script lang="ts" setup>
import RightTabs from '@/components/RightTabs/RightTabs.vue';
import { traduction } from '@/utils/language';

import { useRouter } from 'vue-router';
import { UserPrivil } from '@/model/base-enum';
import { checkPrivil } from '@/apps/app-bmc/router/routes';
import { onMounted } from 'vue';

const $router = useRouter();
const OPERATE_LOG = traduction('OPERATE_LOG');
const RUNNING_LOG = traduction('RUNNING_LOG');
const SERCURITY_LOG = traduction('SERCURITY_LOG');
// 安全配置权限
const securityConfig = checkPrivil(UserPrivil.securityConfig);

let checkTabIndex = '1';
const all = [
  {
    index: '1',
    label: 'OPERATE_LOG',
    router: '/navigate/maintenance/bmc-logs/operation',
    id: 'operationLog',
  },
  {
    index: '2',
    label: 'RUNNING_LOG',
    router: '/navigate/maintenance/bmc-logs/run',
    id: 'runLog',
  },
  {
    index: '3',
    label: 'SERCURITY_LOG',
    router: '/navigate/maintenance/bmc-logs/security',
    id: 'securityLog',
  },
];
const restrict = [
  {
    index: '1',
    label: 'RUNNING_LOG',
    router: '/navigate/maintenance/bmc-logs/run',
    id: 'runLog',
  },
];
let tabList = securityConfig ? all : restrict;
let currentRoute = $router.currentRoute.value.fullPath;
const currentTabItem = tabList.find(item => {
  return item.router === currentRoute;
});
if (currentTabItem) {
  checkTabIndex = currentTabItem.index;
}

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="info-box">
    <!-- tab切换区域 -->
    <RightTabs :check-tab-index="checkTabIndex" :tab-list="tabList" @handle-select="handleSelect" />
    <router-view />
  </div>
</template>

<style lang="scss" scoped>
.info-box {
  flex: 1;
  display: flex;
  flex-direction: column;

  .el-menu {
    margin-right: 24px;
  }
}
</style>
