<template>
  <div
    :style="{
      top:
        settingsStore.navigationType === 'left-menu-type'
          ? '0px'
          : settingsStore.navigationType === 'top-menuMix-type'
          ? '56px'
          : settingsStore.navigationType === 'top-menu-type'
          ? '56px'
          : '',
    }"
  >
    <logo
      v-if="settingsStore.navigationType !== 'top-menu-type'"
      :collapse="isCollapse"
    />
    <el-scrollbar class="sidebar-menu-container" wrap-class="scrollbar-wrapper" :class="[settingsStore.navigationType === 'left-menu-type'
          ? 'left-menu-type' : 'other',]">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :unique-opened="true"
        :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 setup>
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import { usePermissionStore, useSettingsStore, useAppStore } from "@/store/modules/index";

const route = useRoute();
const appStore = useAppStore();
const settingsStore = useSettingsStore();
const permissionStore = usePermissionStore();
const sidebarRouters = computed(() => permissionStore.sidebarRouters);
const isCollapse = computed(() => !appStore.sidebar.opened);

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>
