<template>
  <div class="sidebar-wrapper" :style="{ backgroundColor: '#fff' }">
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="'#fff'"
        :text-color="'#555'"
        :unique-opened="true"
        :active-text-color="'#4F46E5'"
        :collapse-transition="false"
        mode="vertical"
        class="sidebar-menu"
      >
        <sidebar-item
          v-for="(route, index) in sidebarRouters"
          :key="route.path  + index"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
import SidebarItem from "./SidebarItem";

export default {
  components: { SidebarItem },
  computed: {
    ...mapState(["settings"]),
    ...mapGetters(["sidebarRouters", "sidebar"]),
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
      return path;
    },
    isCollapse() {
      return !this.sidebar.opened;
    }
  }
};
</script>

<style lang="scss" scoped>
.sidebar-wrapper {
  width: 200px;
  height: 100%;
  background: #fff;
  border-right: 1px solid #f0f0f0;

  .sidebar-menu {
    border: none;
    height: 100%;
    width: 100% !important;

    ::v-deep .el-menu-item {
      height: 44px;
      line-height: 44px;
      font-size: 14px;
      color: #555;
      padding-left: 20px !important;

      &:hover {
        background-color: rgba(79, 70, 229, 0.04) !important;
      }

      &.is-active {
        color: #4F46E5 !important;
        background-color: #EDE9FE !important;
        border-radius: 0;
        font-weight: 500;
      }
    }

    ::v-deep .el-submenu__title {
      height: 44px;
      line-height: 44px;
      font-size: 14px;
      color: #555;
      padding-left: 20px !important;
      font-weight: 500;

      &:hover {
        background-color: rgba(79, 70, 229, 0.04) !important;
      }

      .svg-icon {
        margin-right: 10px;
        font-size: 16px;
      }
    }

    ::v-deep .el-submenu .el-menu-item {
      padding-left: 44px !important;
      font-size: 14px;
      font-weight: 400;
      min-width: auto !important;
    }

    ::v-deep .el-submenu .el-submenu .el-menu-item {
      padding-left: 60px !important;
    }
  }
}
</style>
