<template>
  <div
    :class="{ 'has-logo': showLogo }"
    :style="{ backgroundColor: this.themeMenuBg() }"
  >
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="this.themeMenuBg()"
        :text-color="this.themeTextColor()
        "
        :unique-opened="true"
        :active-text-color="settings.theme"
        :collapse-transition="false"
        mode="vertical"
      >
        <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 Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/assets/styles/variables.scss";

export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapState(["settings"]),
    ...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;
    },
  },
  methods: {
    themeMenuBg() {
      switch (this.settings.sideTheme) {
        case "theme-dark":
          return variables["menuBg"];
        case "theme-light":
          return variables["menuLightBg"];
        case "theme-N1":
          console.log(variables["menuN1Bg"])
          return variables["menuN1Bg"];
      }
    },
    themeTextColor() {
      switch (this.settings.sideTheme) {
        case "theme-dark":
          return variables["menuText"];
        case "theme-light":
          return "rgba(0,0,0,.65)";
        case "theme-N1":
          return variables["menuText"];
      }
    },
  },
};
</script>
