<template>
  <div :class="{ 'has-logo': showLogo }" :style="sidebarStyle">
    <div class="logo-container">
      <img
        v-show="isCollapse"
        src="../../../../static/login/img/goelie-b.png"
        class="sidebar-logo"
      />
      <h3 class="title" v-show="!isCollapse">歌莉娅AI营销平台</h3>
    </div>
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :unique-opened="false"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item
          v-for="route in permissionRoutes"
          :key="route.path"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

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

export default {
  components: { SidebarItem },
  computed: {
    ...mapGetters(["permissionRoutes", "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;
    },
    isCollapse() {
      return !this.sidebar.opened;
    },
    sidebarStyle() {
      return {
        width: this.isCollapse ? "64px !important;" : "230px;",
        transition: "width 0.3s"
      };
    }
  }
};
</script>
<style lang="scss" scoped>
.logo-container {
  height: 60px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;

  .sidebar-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
  }
}

.title {
  color: #000000cc;
  font-size: 17px;
  text-align: center;
}
</style>
