<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" :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 {
  data () {
    return {
      leup: true,
    };
  },
  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;
    },
  },
};
</script>

<style lang="scss" scoped>
.rloop {
  width: 8px;
  height: 100%;
  position: absolute;
  // background: #2d67e3;
  z-index: 999;
  right: 0;
  top: 0;
  > .log_open {
    width: 8px;
    height: 144px;
    background: #385086;
    border-radius: 0px 8px 8px 0px;
    position: absolute;
    top: 42%;
    right: -8px;
    display: flex;
    align-items: center;
    > .arrows {
      width: 6px;
      height: 6px;
      background: url("../../../assets/logo/ic_arrow_left.png") no-repeat;
    }
    > .arrow {
      width: 6px;
      height: 6px;
      background: url("../../../assets/logo/ic_arrow_right.png") no-repeat;
    }
    // border-top-right-radius: 12px;
    // border-bottom-right-radius: 12px;
  }
  // > .log_open:hover {
  //   background: #2d67e3;
  //   > .rloop {
  //     background: #2d67e3;
  //   }
  // }
  &:hover {
    background: #2d67e3;
    > .log_open {
      background: #2d67e3;
    }
  }
  > img {
    width: 20px;
    height: 20px;
    position: absolute;
    top: 45%;
    right: -10px;
  }
}
::v-deep .navMenu {
  .router-link-active {
    .account {
      background: url("../../../assets/nav/ic_list_nav_account_check.png")
        no-repeat;
    }
    .accountgroup {
      background: url("../../../assets/nav/ic_list_nav_group_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;
    }
    .BasicsData {
      background: url("../../../assets/nav/ic_data_collection_check.png")
        no-repeat;
    }

    .systemSettings {
      background: url("../../../assets/nav/ic_setting_nav_check.png") no-repeat;
    }
    .statisticsCharts {
      background: url("../../../assets/nav/ic_list_nav_statistical_check.png")
        no-repeat;
    }
    .statisticalAnalysis {
      background: url("../../../assets/nav/ic_list_nav_screen_check.png")
        no-repeat;
    }
  }
}
</style>
