<template>
  <div>
    <v-list class="side-box" color="primary">
      <template v-for="(item, index) in list">
        <template v-if="!item.children.length">
          <v-list-item
            :key="`${item.name}_${index}`"
            active-class="active"
            color="primary"
            :href="item.path"
            :to="item.path"
            rounded="shaped"
            :prepend-icon="item.icon"
            :title="getCurrentLocaleLang() === 'zh_CN' ? item.title : item.enName"
          >
          </v-list-item>
        </template>
        <v-list-group
          v-else
          color="primary"
          rounded="shaped"
          :key="`${item.path}_${item.title}`"
          :prepend-icon="item.icon"
        >
          <template v-slot:activator="{ props }">
            <v-list-item v-bind="props" :title="getCurrentLocaleLang() === 'zh_CN' ? item.title : item.enName"></v-list-item>
          </template>
          <v-list-item
            v-for="(val, i) in item.children"
            :key="i"
            color="primary"
            :href="val.path"
            style="padding-left: 40px;"
            :to="val.path"
            :title="getCurrentLocaleLang() === 'zh_CN' ? val.title : val.enName"
            rounded="shaped"
          ></v-list-item>
        </v-list-group>
      </template>
    </v-list>
  </div>
</template>

<script setup>
defineOptions({ name: 'enterprise-side'})
import { computed } from 'vue'
import { getCurrentLocaleLang } from '@/utils/lang.js'
// import enterpriseRoute from '@/router/modules/components/recruit/enterprise'
import { useEnterpriseStore } from '@/store/enterprise'

const enterpriseStore = useEnterpriseStore()
const list = computed(() => {
  return getList(enterpriseStore.enterpriseMenu)
})
// console.log(import.meta.env.VITE_NODE_ENV, '当前环境变量============')

// const isAdmin = localStorage.getItem('isAdmin') === '1'
// const info = localStorage.getItem('entBaseInfo') ? JSON.parse(localStorage.getItem('entBaseInfo')) : {}
const getList = (arr, obj = [], root = '') => {
  // 是否为企业管理员
  arr.forEach(element => {
    if (!element.alwaysShow) return
    let data = {}
    // const path = element.path[0] === '/' ? element.path : '/' + element.path
    const path = root + element.path
    data = {
      title: element.name,
      enName: element?.meta?.enName,
      icon: element.icon,
      name: element.name,
      path: enterpriseStore.menuType.CATALOGUE === element.type ? path + '/index' : path,
      children: []
    }
    // if (element?.meta?.isAdmin) {
    //   data.isAdmin = true
    // }
    // 人才地图
    // if (element?.meta?.isPersonMap) data.isPersonMap = true
    // 全员猎寻
    // if (element?.meta?.hireJob) data.hireJob = true
    if (element?.children) {
      getList(element.children, data.children, path + '/')
    }
    obj.push(data)
  })
  // if (!isAdmin) {
  //   obj = obj.filter(e => !e.isAdmin)
  //   obj.map(e => {
  //     e.children = e.children.filter(val => !val.isAdmin)
  //   })
  // }
  // 人才地图是否可看
  // if (info && Object.keys(info).length && !info?.entitlement?.personMap) obj = obj.filter(e => !e.isPersonMap)
  // 全员猎寻是否可看
  // if (info && Object.keys(info).length && !info?.entitlement?.hireJob) obj = obj.filter(e => !e.hireJob)

  // 生产环境隐藏门墩儿新任命
  if (import.meta.env.VITE_NODE_ENV === 'production') obj = obj.filter(e => !e.path.includes('/recruit/enterprise/newlyAppointed'))
  return obj
}

</script>

<style scoped lang="scss">
.side-box {
  width: 230px;
  height: 100%;
}
</style>
