<script setup lang="ts">
import { computed } from 'vue'
import SidebarItem from '../sidebar-item/index.vue'
import { routes } from '@/router/routes'

import { useRoute } from 'vue-router'

const route = useRoute()

const activeMenu = computed(() => {
  const { path, meta } = route
  // 提取基础路径（去掉参数）
  const basePath = path.split('?')[0].split('/').slice(0,4).join('/')
  return meta.activeMenu || basePath
})

const subMenuList = computed(() => {
  const data = routes.filter((el:any) => el.meta && !el.meta.hidden ) // getChildRouteListByPathAndName(meta.parentPath, meta.parentName)
  return data
})

defineOptions({
  name: 'AppSidebar'
})

</script>

<template>
    <el-menu 
        :default-active="activeMenu" 
        :default-openeds="['/smart', '/knowledge']"
        router 
        :collapse-transition="false"
        :unique-opened="false"
    >
        <sidebar-item
            v-for="(menu) in subMenuList"
            :key="menu.path"
            :menu="menu"
            :activeMenu="activeMenu"
        >
        </sidebar-item>
    </el-menu>
</template>

<style lang="scss">
// @import '../index.scss';
</style>
