<template>
  <div class="sidebar-shell">
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <div class="sidebar-shell">
        <div v-show="showBrand" class="img-wrapper">
          <img :src="require('@/assets/img/LOGO1.png')" class="brand-logo" alt="WODEER MES">
        </div>
        <el-menu
          :show-timeout="200"
          :default-active="$route.path"
          :collapse="isCollapse"
          :style="menuStyle"
          class="sidebar-menu"
          mode="vertical"
          background-color="transparent"
          text-color="#31456a"
          active-text-color="#ffffff"
        >
          <sidebar-item v-for="route in permission_routers" :key="route.name" :item="route" :base-path="route.path"/>
        </el-menu>
      </div>
    </el-scrollbar>
  </div>
</template>

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

export default {
  components: { SidebarItem },
  computed: {
    ...mapGetters([
      'sidebar',
      'permission_routers'
    ]),
    routes() {
      return this.$router.options.routes
    },
    isCollapse() {
      return !this.sidebar.opened
    },
    showBrand() {
      return this.sidebar.opened
    },
    menuStyle() {
      return {
        height: this.sidebar.opened ? 'calc(100% - 128px)' : 'calc(100% - 12px)'
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .sidebar-shell {
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }

  .img-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 10px 18px;
    padding: 12px 10px;
    min-height: 76px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: inset 0 0 0 1px rgba(145, 178, 233, 0.18);
  }

  .brand-logo {
    display: block;
    max-width: 100%;
    height: 49px;
    object-fit: contain;
  }

  .sidebar-menu {
    flex: 1;
  }
</style>
