<template>
  <el-scrollbar wrap-class="scrollbar-wrapper">
    <el-menu
      :show-timeout="200"
      :default-active="$route.path"
      :collapse="isCollapse"
      mode="vertical"
      background-color="#304156"
      text-color="#bfcbd9"
      active-text-color="#409EFF"
    >
        <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path"/>
    </el-menu>
  </el-scrollbar>
</template>

<script>
import { mapGetters } from 'vuex'
import SidebarItem from './SidebarItem'

export default {
    components: { SidebarItem },
    computed: {
    ...mapGetters([
        'sidebar',
        'roles'
    ]),
    routes: function () {
        // console.log(this.roles)
        console.log(11)
        let routes = this.$router.options.routes
        console.log(routes)
        routes.forEach((item, i)=>{
            if(!item.hidden) {
                let title = item.children.length==1 ? item.children[0].meta.title : item.meta.title
                let arr = this.roles.filter((data)=> { return data.content==title })
                // console.log(item, arr, arr.length==0)
                if(arr.length==0) {
                    routes[i].hidden = true
                }
                // if(item.children.length==1) {
                //     console.log(item.children[0].meta.title)
                // } else {
                //     console.log(item.meta.title)
                // }
            }
        })
        return routes
    },
    isCollapse() {
      return !this.sidebar.opened
    }
  }
}
</script>
