<template>
  <div :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
       <!-- :default-active="activeMenu" -->
       <!-- default-active="/home" -->
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color=" $store.state.settings.themeStyle === 'light' ? variables.menuLightBg : variables.menuBg"
        :text-color="$store.state.settings.themeStyle === 'light' ? 'rgba(0,0,0,.65)' : '#fff'"
        :active-text-color="$store.state.settings.theme"
        :unique-opened="true"
        :collapse-transition="true"
        mode="vertical"
        router
      >
        <sidebar-item
          v-for="(route) in sidebarRouters"
          :key="route.path+Math.random()"
          :item="route"
          :base-path="route.path"
        />
        <!-- <el-menu-item index="/home">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </el-menu-item> -->
        <!-- <el-menu-item index="/home">
          <i class="el-icon-s-grid"></i>
          <span slot="title">应用分析</span>
        </el-menu-item> -->

      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss'

export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters([
      'sidebarRouters',
      'sidebar'
    ]),
    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    },
    showLogo() {
      return this.$store.state.settings.sidebarLogo
    },
    variables() {
      return variables
    },
    isCollapse() {
      return !this.sidebar.opened
    }
  },
  mounted() {

  },
  methods: {

  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-menu--collapse > .el-menu-item [class^=el-icon-],::v-deep .el-menu--collapse > .el-submenu > .el-submenu__title [class^=el-icon-] {
    vertical-align: middle;
    width: 24px;
    text-align: center;
    margin-left: -5px !important;
}
::v-deep .el-menu-item {
  // text-align: center;
  text-align: left;
}
</style>
