<template>
  <div :class="{ 'has-logo': showLogo }">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        class="navMenu"
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="variables.menusBg"
        :text-color="variables.menuText"
        :unique-opened="false"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item
          v-for="(route, index) in permission_routes"
          :key="index"
          :item="route"
          :base-path="route.path"
          :leup="leup"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/styles/variables.scss";

export default {
  props: {
    // route object
    leup: {
      type: Boolean,
      default: false,
    },
  },
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters(["sidebar", "permission_routes"]),
    routes() {
      const power =
        typeof this.userPowerList == "string"
          ? JSON.parse(this.userPowerList)
          : this.userPowerList;
      return power;
      // const datas = this.$router.options.routes;
      // const arrs = [];
      // const menus = [];
      // if (power && power.length) {
      //   for (const item of datas) {
      //     if (item.meta) {
      //       arrs.push(item);
      //     }
      //   }
      //   arrs.forEach(item => {
      //     power.forEach(p => {
      //       if (item.meta.isModule == p) {
      //         menus.push(item);
      //       }
      //     })
      //   })
      //   return menus;
      // } else {
      //   return datas;
      // }
    },
    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;
    },
    variables() {
      return variables;
    },
    isCollapse() {
      return !this.sidebar.opened;
    },
  },
  watch: {
    leup() {
      console.log(this.leup);
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .navMenu {
  .router-link-active {
    .account {
      background: url("../../../assets/nav/ic_list_nav_account_check.png")
        no-repeat;
    }
    .role {
      background: url("../../../assets/nav/ic_list_nav_character_check.png")
        no-repeat;
    }
    .authority {
      background: url("../../../assets/nav/ic_list_nav_permissions_check.png")
        no-repeat;
    }
    .transfer {
      background: url("../../../assets/nav/ic_list_nav_transit_check.png")
        no-repeat;
    }
    .arrival {
      background: url("../../../assets/nav/ic_list_nav_arrive_check.png")
        no-repeat;
    }
    .departure {
      background: url("../../../assets/nav/ic_list_nav_leave_check.png")
        no-repeat;
    }
    .dataCollection {
      background: url("../../../assets/nav/ic_data_collection_check.png")
        no-repeat;
    }
    .dataParser {
      background: url("../../../assets/nav/ic_data_governance_check .png")
        no-repeat;
    }
    .dataStore {
      background: url("../../../assets/nav/ic_data_save_check.png") no-repeat;
    }
    .dashboard {
      background: url("../../../assets/nav/ic_setting_nav_check.png") no-repeat;
    }
    .advance {
      background: url("../../../assets/nav/ic_list_nav_search_check.png")
        no-repeat;
    }
    .integration {
      background: url("../../../assets/nav/ic_data_governance_check .png")
        no-repeat;
    }
    .protocol {
      background: url("../../../assets/nav/ic_list_nav_agreement_check.png")
        no-repeat;
    }
    .deployNode {
      background: url("../../../assets/nav/ic_list_nav_node_check.png")
        no-repeat;
    }
    .sourceDataItem {
      background: url("../../../assets/nav/ic_list_nav_source_check.png")
        no-repeat;
    }
  }
}
</style>
