<template>
  <div :class="{ 'has-logo': showLogo }">
    <el-menu
      :default-active="activeMenu"
      :unique-opened="false"
      :collapse-transition="false"
      mode="horizontal"
      :background-color="variables.menuBg"
      :text-color="variables.menuText"
      :active-text-color="variables.menuActiveText"
      class="frame-menu"
    >
      <sidebar-item
        v-for="route in routes"
        :key="route.path"
        :item="route"
        :base-path="route.path"
        ref="list"
      />
    </el-menu>
  </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([
      'sidebar'
    ]),
    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
    },
  }
}
</script>
<style lang="scss" scoped>
.frame-menu {
  border: none;
  height: 100%;
  width: 100% !important;
  white-space: nowrap;
  &.el-menu--horizontal {
    border-bottom: none !important;
    > .menu-wrapper {
      display: inline-block;
      > a {
        // display: inline-block;
        > .el-menu-item {
          display: inline-block;
          margin: 0;
          border-bottom: 2px solid transparent;
          padding: 0 5px;
        }
      }
      > .el-submenu {
        display: inline-block;
        .el-submenu__title {
          border-bottom: 2px solid transparent;
          padding: 0 5px;

          // &:hover {
          //   background-color: #fff;
          // }
        }
        .el-submenu__icon-arrow {
          position: static;
          vertical-align: middle;
          margin-left: 8px;
          margin-top: -3px;
        }
      }
    }
  }
  &.el-menu--collapse > .menu-wrapper {
    > a > .el-menu-item span,
    > .el-submenu > .el-submenu__title span {
      height: 0;
      width: 0;
      overflow: hidden;
      visibility: hidden;
      display: inline-block;
    }
    > a > .el-menu-item .el-submenu__icon-arrow,
    > .el-submenu > .el-submenu__title .el-submenu__icon-arrow {
      display: none;
    }
  }
  .el-submenu.is-active > .el-submenu__title {
    color: #fff !important;
  }
}
</style>