<template>
  <div style="height: 100%; position: relative;" class="sidebar-bg">
    <!-- <div class="sidebar-title">
      <img :src="logoImage" style="width: 32px; height: 32px; border-radius: 50%;" />
      <p class="sidebar-title-text">{{getProjectName()}}</p>
    </div> -->
    <multiColumn v-if="getMultiColumn" :menuList="getMenuList"/>
    <div v-else class="left-menu" :class="getCollapse ? 'collapse' : ''" style="height: 100%; padding-bottom: 60px;padding-top: 16px;">
      <el-scrollbar wrap-class="scrollbar_dropdown__wrap" style="height: 100%;">
        <el-menu ref="menu" mode="vertical" :default-active="getCurrentMenuId" :unique-opened="true" @select="selectMenu"
          :active-text-color="activeTextColor" :collapse="getCollapse" >
          <div v-for="menu in getMenuList" :key="menu.menuId">
            <menu-item :menu="menu"  />
          </div>
        </el-menu>
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
import menuItem from './menu-item.vue';
import multiColumn from './multi-column.vue';

import { mapGetters, mapMutations } from 'vuex';
import projectConfig from '@/core/config';

export default {
  data () {
    return {
      isCollapse: false,
      collapseLeft: '200px',
      showCollapseBtn: true,
      logoImage: require('../../../../assets/img/logo.png')
    }
  },
  components: {
    'menu-item': menuItem,
    multiColumn
  },
  computed: {
    activeTextColor () {
      return undefined;
    },
    getCollapseStyle () {
      return [{
        left: this.collapseLeft
      }]
    },
    ...mapGetters(['getMultiTags', 'getMenuList', 'getCollapse', 'getCurrentMenuPath', 'getCurrentMenuId', 'getMultiColumn'])
  },
  methods: {
    onCollapseChange () {
      this.showCollapseBtn = false;
      setTimeout(() => {
        this.setCollapse(!this.getCollapse);
        this.collapseLeft = this.getCollapse ? '65px' : '200px';
        this.showCollapseBtn = true;
      }, 100);
    },
    getProjectName () {
      if (this.getCollapse) {
        return projectConfig.projectName.substr(0, 1);
      } else {
        return projectConfig.projectName;
      }
    },
    selectMenu (index, path) {
      if (this.getCurrentMenuId === index) return;
      // 单页面清空所有tags和cachePage
      if (!this.getMultiTags) {
        this.clearAllTags();
      }
      this.setCurrentMenuId(index);
    },
    ...mapMutations(['setCollapse', 'clearAllTags', 'setCurrentMenuId'])
  }
};
</script>

<style lang="scss">
@import '@/assets/style/element-variables.scss';
  .sidebar-title-text {
    font-size: 18px;
    font-weight: bold;
  }
  .left-menu .el-submenu__title {
    color: #43474E;
    height: 50px;
    line-height: 50px;
    background: $--color-menu-background ;
    i{
      color: #43474E !important;
    }
    .el-submenu__icon-arrow{
      margin-top: -4px;
    }
  }
  .sidebar-bg{
    .el-menu-item{
      color: #43474E;
      background: $--color-menu-background ;
    }
  }
  .collapse .is-active .el-submenu__title{
    position: relative;
    background-color:  $--color-menu-background !important;
    &::before{
      content: '';
      display: block;
      width: 4px;
      height: 100%;
      background: $--color-menu-background;
      position: absolute;
      left: 0;
      top: 0;
    }
    i {
    color:$--color-primary !important;;
    
}
  }
  .collapse .el-icon-arrow-right{
    display: none;
  }
  .el-menu-item:hover,.el-submenu__title:hover{
    background-color: #fff !important;
    color: $--color-primary !important;
    i {
    color: $--color-primary !important;
}
  }
  .el-menu-item.is-active{
    background-color: #fff !important;
    border-radius: 4px;
    color: white !important;
    &::before{
      content: '';
      display: block;
      width: 4px;
      height: 100%;
      background: $--color-menu-item-active-background-to !important;
      position: absolute;
      left: 0;
      top: 0;
    }
    i{
      color: white !important;
    }
  }
  .el-menu--vertical .el-submenu__title{
    &>span{
      display: inline !important;
    }
  }
  .el-menu--vertical .el-menu.el-menu--popup{
    background-color: white !important;
    padding: 16px 8px;
    .el-menu-item, .el-submenu__title{
      color: #333333;
      padding: 0 3px !important;
      height: 40px;
      line-height: 40px;
      &::before{
        display: none;
      }
      &:hover{
        background-color: #F6F6F6 !important;
        &>.multi-column-menu-popover{
          display: block;
        }
      }
      &.is-active{
        color: #Fff !important;
        background-color: $--color-primary-light-9 !important;

      }
      .el-submenu__icon-arrow{
        margin-top: -5px;
        color: #333333;
      }
    }
    .el-menu--vertical{
      transform: translateX(6px);
    }
  }
  .menu-wrapper{
    background: $--color-menu-background;
  }
  /*
  .el-menu .menu-wrapper>.el-menu-item{
    padding-left: 36px !important;
  }
  */
  // .el-submenu {
  //   .el-menu {
  //     background-color: #fff !important;
  //   }
  //   background-color: #fff !important;
  // }
</style>
