<template>
  <el-container :class="{'has-logo':showLogo}">
    <el-header style="padding: 0; height: auto;"> <logo v-if="showLogo" :collapse="isCollapse" /></el-header>
    <el-main style="padding: 0;">
      <el-scrollbar wrap-class="scrollbar-wrapper">
        <el-menu
          :default-active="activeMenu"
          :collapse="isCollapse"
          :background-color="variables.menuBg"
          :text-color="variables.menuText"
          :unique-opened="false"
          :active-text-color="variables.menuActiveText"
          :collapse-transition="false"
          mode="vertical"
        >
          <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
        </el-menu>
      </el-scrollbar>
    </el-main>
    <el-footer class="Efooter" style="padding:2% 0 10% 0; min-height: 5%;">
      <el-divider style="color: #EEF0F5; margin: 0px;" />
      <hamburger :is-active="sidebar.opened" class="hamburger-containers" @toggleClick="toggleSideBar" />
    </el-footer>
  </el-container>
</template>

<script>
import { mapGetters } from 'vuex'
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss'
import { logoutUrl } from '@/apiConfig/requestIP.js'
import Hamburger from '@/components/Hamburger'

export default {
  components: { SidebarItem, Logo, Hamburger },
  computed: {
    ...mapGetters([
      'sidebar',
      'routes'
    ]),
    // routes() {
    //   return this.$router.options.routes
    // },
    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
    }
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    Logout() {
      location.href = logoutUrl
    }
  }
}
</script>
<style>
  .hamburger-containers {
    line-height: 46px;
    height: 100%;
    float: right;
    cursor: pointer;
    -webkit-tap-highlight-color:transparent;
    padding: 0px 20px !important;
    color: red !important;
    background: #FFF !important;
  }
  .Efooter .el-divider--horizontal {
    display: block;
    height: 1px;
    width: 100%;
    margin: 0;
}

</style>

<style lang="stylus">
  .btn span {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .el-submenu__title i {
    color: #333B4A;
}
</style>
