<template>
  <div class="sidebar-container">
    <div class="sidebar-container-header">
      <div class="sidebar-container-header-title">
        <div class="pic-box cp" @click="$router.push(sideBarParams.logoLink || '/')" v-if="sideBarParams.logoSrc">
          <img :src="sideBarParams.logoSrc || 'https://assets.ftlapp.io/ui/berry-logo.png'" alt="" class="logo" />
        </div>
        <div class="ftl-pic-box cp" @click="$router.push(sideBarParams.logoLink || '/')" v-if="!sideBarParams.logoSrc">
          <img src="https://assets.ftlapp.io/ui/berry-logo.png" alt="" class="logo" />
        </div>
        <span class="title cp" @click="$router.push(sideBarParams.logoLink || '/')" v-if="collapse">{{
          sideBarParams.logoName
        }}</span>
        <div class="sidebar-container-header-title-right" v-if="collapse">
          <div
            v-if="!sideBarParams.isProd"
            class="environment"
            :style="`margin-top:${!sideBarParams.projectEntry ? -20 : 0}px`"
          >
            STAGING
          </div>
          <ftl-entry v-if="sideBarParams.projectEntry" v-bind="$attrs" />
        </div>
      </div>
    </div>
    <el-menu
      class="el-menu-vertical-demo"
      :collapse="!collapse"
      @select="menuClick"
      :default-active="$route.meta.parentName ? $route.meta.parentName : $route.name"
    >
      <side-menus :menus="showMenus" v-if="showMenus && showMenus.length" />
    </el-menu>
  </div>
</template>
<script>
import FtlEntry from "../../FtlEntry/src/index.vue";
import SideMenus from "./sideMenus.vue";
import { mapState } from "vuex";
export default {
  name: "FtlSidebar",
  components: { FtlEntry, SideMenus },
  props: {
    sideBarParams: {
      type: Object,
      default: () => ({}),
    },
    collapse: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      showMenus: [],
    };
  },
  computed: {
    ...mapState("auth", ["menus"]),
  },
  created() {
    this.refreshMenu()
  },
  methods: {
    menuClick(index) {
      this.$router.push({ name: index });
    },
    refreshMenu(){
      this.showMenus = JSON.parse(JSON.stringify(this.menus)) || [];
    }
  },
};
</script>
<style lang="scss" scoped>
$bg: #293948;

.sidebar-container {
  &-header {
    display: flex;
    justify-content: center;
    align-items: center;
    &-title {
      display: flex;
      align-items: center;
      .title {
        font-weight: 600;
        font-size: 22px;
        margin-left: 5px;
      }
      &-right {
        margin-left: 10px;
        text-align: center;
      }
      .environment {
        font-size: 12px;
        font-weight: bold;
        font-style: italic;
      }
    }
  }
}
.el-menu-vertical-demo {
  height: calc(100vh - 68px);
  overflow-y: auto;
  overflow-x: hidden;
  &::-webkit-scrollbar {
    width: 0;
  }
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
}
</style>
