<template>
  <div :class="{ 'has-logo': true, 'is_sidebar-hide': sidebar.hide }" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
    <!-- <logo v-if="showLogo" :collapse="isCollapse" /> -->
    <div class="classify-menu">
      <classifyMenu></classifyMenu>
    </div>
    <el-scrollbar v-if="!sidebar.hide" :class="sideTheme" wrap-class="scrollbar-wrapper">
      <div class="menu-module">
        <span class="module-icon-box">
          <svg-icon v-if="sidebar.currentModule && sidebar.currentModule.meta" :icon-class="sidebar.currentModule.meta.icon" color="#ffffff" class="module-icon" />
        </span>
        <span class="sidebar-title" v-if="sidebar.currentModule && sidebar.currentModule.meta">{{ sidebar.currentModule.meta.title }}</span>
      </div>
      <el-menu
        :default-active="activeMenu"
        :background-color="sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
        :text-color="sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
        :unique-opened="true"
        :active-text-color="theme"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item
          v-for="(route, index) in sidebarRouters"
          :key="route.path + index"
          :item="route"
          :base-path="route.path"
          class="sidebar-item-info"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script setup>
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '@/assets/styles/variables.module.scss'
import useAppStore from '@/store/modules/app'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
import classifyMenu from './classifyMenu.vue'
const route = useRoute();
const appStore = useAppStore()
const settingsStore = useSettingsStore()
const permissionStore = usePermissionStore()

const sidebarRouters =  computed(() => permissionStore.sidebarRouters);
const showLogo = computed(() => settingsStore.sidebarLogo);
const sideTheme = computed(() => settingsStore.sideTheme);
const theme = computed(() => settingsStore.theme);
const isCollapse = computed(() => !appStore.sidebar.opened);
const sidebar = computed(() => useAppStore().sidebar);

const activeMenu = computed(() => {
  const { meta, path } = route;
  // if set path, the sidebar will highlight the path you set
  if (meta.activeMenu) {
    return meta.activeMenu;
  }
  return path;
})
</script>
<style lang="scss" scoped>
.classify-menu{
  width: 70px;
  height: calc(100% - 56px);
  background: #ECEFF3;
}
.is_sidebar-hide{
  width: 70px !important;
}
.scrollbar-wrapper{
  .menu-module{
    width: 100%;
    height: 56px;
    font-size: 16px;
    font-weight: 600;
    line-height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid #DFE1E4;
    .module-icon-box{
      display: inline-block;
      width: 28px;
      height: 28px;
      background: #39BA15;
      border-radius: 16px;
      line-height: 28px;
      text-align: center;
      margin-right: 12px;
      .module-icon{
        font-size: 16px;
        margin: 0 !important;
      }
    }
    .sidebar-title{
      vertical-align: middle;
    }
  }
}
</style>