<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, computed } from 'vue';
import { getStoreData } from '@/utils/composition';


const $router = useRouter();
const OPERATE_LOG = traduction('OPERATE_LOG');
const RUNNING_LOG = traduction('RUNNING_LOG');
const SERCURITY_LOG = traduction('SERCURITY_LOG');
const assetChangeEnabled = computed(() => getStoreData('loct', 'assetChange'));


let checkTabIndex = '0';
const all = [
  {
    index: '0',
    label: 'ASSET_INVENTORY',
    router: '/navigate/maintenance/asset-maintance/asset-inventory',
    id: 'assetInventory1',
  },
  {
    index: '1',
    label: 'ASSET_MAINTANCE_CHANGE',
    router: '/navigate/maintenance/asset-maintance/asset-change',
    id: 'assetChange2',
  },
  {
    index: '3',
    label: 'ASSET_MAINTANCE_SCAPPING',
    router: '/navigate/maintenance/asset-maintance/asset-retire',
    id: 'assetMaintance0',
  },
];

let tabList = all;
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(() => {
  if (!assetChangeEnabled.value) {
    tabList.splice(1, 1);
  }
});
</script>

<template>
  <div id="assetMaintanceViewID" class="assetMaintance">
    <!-- tab切换区域 -->
    <RightTabs :check-tab-index="checkTabIndex" :tab-list="tabList" @handle-select="handleSelect" />
    <router-view />
  </div>
</template>

<style lang="scss" scoped>
.assetMaintance {
  flex: 1;
  margin-right: 24px;
  display: flex;
  flex-direction: column;

  :deep(.el-table + .el-pagination) {
    margin-top: 16px;
  }
}
</style>