<template>
  <div v-if="!item.hidden">
    <template v-if="hasOneShowingChild(item.children, item)">
      <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
        <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }">
          <item :icon="onlyOneChild.meta.elSvgIcon||(item.meta&&item.meta.elSvgIcon)" :title="item.meta.title" />
        </el-menu-item>
      </app-link>
    </template>

    <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
      <template v-if="item.meta" slot="title">
        <item :meta="item.meta" />
        <span>{{ item.meta.title }}</span>
      </template>
      <SidebarItem v-for="child in item.children" :key="child.path" :is-nest="true" :item="child" :base-path="resolvePath(child.path)" />
    </el-submenu>
  </div>
</template>

<script>
import path from "path";
import { isExternal } from "@/utils/validate";
import Item from './Item'
import AppLink from "./Link";
import FixiOSBug from "./FixiOSBug";

export default {
  name: "SidebarItem",
  components: {
    Item,
    AppLink,
  },
  mixins: [FixiOSBug],
  props: {
    // route object
    item: {
      type: Object,
      required: true,
    },
    isNest: {
      type: Boolean,
      default: false,
    },
    basePath: {
      type: String,
      default: "",
    },
    leup: {
      type: Boolean,
      default: true,
    },
  },
  data () {
    // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
    // TODO: refactor with render function
    this.onlyOneChild = null;
    return {};
  },
  mounted () {
    // 
    // const vnodes
    // vnodes.push(<span slot='title'>{(title)}</span>)
  },
  methods: {
    hasOneShowingChild (children = [], parent) {
      // 
      const showingChildren = children.filter((item) => {
        if (item.hidden) {
          return false;
        } else {
          this.onlyOneChild = item;
          return true;
        }
      });
      // When there is only one child router, the child router is displayed by default
      if (showingChildren.length === 1) {
        return true;
      }

      // Show parent if there are no child router to display
      if (showingChildren.length === 0) {
        this.onlyOneChild = { ...parent, path: "", noShowingChildren: true };
        return true;
      }

      return false;
    },
    resolvePath (routePath) {
      if (isExternal(routePath)) {
        return routePath;
      }
      if (isExternal(this.basePath)) {
        return this.basePath;
      }
      return path.resolve(this.basePath, routePath);
    },
    getClass (path) {
      const p = path.split("/").join("");
      if (p) {
        return p;
      } else {
        return "advance";
      }
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-menu-item.is-active {
  //设置背景颜色
  background-color: #2d67e3 !important;
  //设置字体颜色
  color: #ffffff !important;
}
.router-link-active > li {
  //设置背景颜色
  background-color: #2d67e3 !important;
  //设置字体颜色
  color: #ffffff !important;
}
// ::v-deep .el-menu-item.is-active:hover {
//   //设置背景颜色
//   background-color: #2d67e3 !important;
//   //设置字体颜色
//   color: #ffffff !important;
// }

// // ::v-deep .el-submenu__title:hover {
// //   background: red !important;
// // }
::v-deep .el-menu-item:hover {
  // background: #2d67e3 !important;
  color: #fff !important;
  .account {
    background: url("../../../assets/nav/ic_list_nav_account_check.png");
  }
  .accountgroup {
    background: url("../../../assets/nav/ic_list_nav_group_check.png");
  }
  .role {
    background: url("../../../assets/nav/ic_list_nav_character_check.png");
  }
  .authority {
    background: url("../../../assets/nav/ic_list_nav_permissions_check.png");
  }
  .transfer {
    background: url("../../../assets/nav/ic_list_nav_transit_check.png");
  }
  .arrival {
    background: url("../../../assets/nav/ic_list_nav_arrive_check.png");
  }
  .departure {
    background: url("../../../assets/nav/ic_list_nav_leave_check.png");
  }
  .dataCollection {
    background: url("../../../assets/nav/ic_data_collection_check.png");
  }
  .dataParser {
    background: url("../../../assets/nav/ic_data_governance_check .png");
  }
  .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");
  }
  .integration {
    background: url("../../../assets/nav/ic_data_governance_check .png");
  }
  .protocol {
    background: url("../../../assets/nav/ic_list_nav_agreement_check.png");
  }

  .deployNode {
    background: url("../../../assets/nav/ic_list_nav_node_check.png");
  }

  .sourceDataItem {
    background: url("../../../assets/nav/ic_list_nav_source_check.png");
  }

  .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;
  }
}
// ::v-deep .el-menu-item {
//   transition: border-color 0.3s, background-color 0s, color 0s;
// }
// ::v-deep .el-submenu__title.is-active {
//   background-color: #6db6ff !important;
// }
// .pathNamecosy:hover {
//   background-image: #2d67e3 !important;
// }
.nav_item {
  width: 36px;
  height: 36px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  margin: auto;
  box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}
.pathName {
  width: 40px;
  height: 40px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  margin: auto;
  background-size: 100% 100%;
  transition: all 0.3s;
}
.pathNamecosy {
  width: 40px;
  height: 40px;
  position: absolute;
  left: -74%;
  right: 0;
  bottom: 0;
  top: 0;
  margin: auto;
  // box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.1);
  background-size: 100% 100%;
  transition: all 0.3s;
}
.pathNameer {
  margin-left: 20%;
}
.pathNameercosy {
  display: none;
}
.account {
  background: url("../../../assets/nav/ic_list_nav_account_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_account_check.png")
      no-repeat;
  }
}
.accountgroup {
  background: url("../../../assets/nav/ic_list_nav_group_default.png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_group_check.png") no-repeat;
  }
}
.role {
  background: url("../../../assets/nav/ic_list_nav_character_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_character_check.png")
      no-repeat;
  }
}
.authority {
  background: url("../../../assets/nav/ic_list_nav_permissions_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_permissions_check.png")
      no-repeat;
  }
}
.transfer {
  background: url("../../../assets/nav/ic_list_nav_transit_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_transit_check.png")
      no-repeat;
  }
}
.arrival {
  background: url("../../../assets/nav/ic_list_nav_arrive_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_arrive_check.png")
      no-repeat;
  }
}
.departure {
  background: url("../../../assets/nav/ic_list_nav_leave_default.png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_leave_check.png") no-repeat;
  }
}
.dataCollection {
  background: url("../../../assets/nav/ic_data_collection_default .png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_data_collection_check.png")
      no-repeat;
  }
}
.dataParser {
  background: url("../../../assets/nav/ic_data_governance_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_data_governance_check .png")
      no-repeat;
  }
}
.dataStore {
  background: url("../../../assets/nav/ic_data_save_default .png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_data_save_check.png") no-repeat;
  }
}
.dashboard {
  background: url("../../../assets/nav/ic_setting_nav_default.png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_setting_nav_check.png") no-repeat;
  }
}
.advance {
  background: url("../../../assets/nav/ic_list_nav_search_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_search_check.png")
      no-repeat;
  }
}
.integration {
  background: url("../../../assets/nav/ic_data_governance_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_data_governance_check .png")
      no-repeat;
  }
}
.protocol {
  background: url("../../../assets/nav/ic_list_nav_agreement_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_agreement_check.png")
      no-repeat;
  }
}

.deployNode {
  background: url("../../../assets/nav/ic_list_nav_node_default.png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_node_check.png") no-repeat;
  }
}

.sourceDataItem {
  background: url("../../../assets/nav/ic_list_nav_source_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_source_check.png")
      no-repeat;
  }
}

.BasicsData {
  background: url("../../../assets/nav/ic_data_collection_default .png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_data_collection_check.png")
      no-repeat;
  }
}

.systemSettings {
  background: url("../../../assets/nav/ic_setting_nav_default.png") no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_setting_nav_check.png") no-repeat;
  }
}

.statisticsCharts {
  background: url("../../../assets/nav/ic_list_nav_statistical_default .png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_statistical_check.png")
      no-repeat;
  }
}

.statisticalAnalysis {
  background: url("../../../assets/nav/ic_list_nav_screen_default.png")
    no-repeat;
  &:hover {
    background: url("../../../assets/nav/ic_list_nav_screen_check.png")
      no-repeat;
  }
}

// .el-tooltip__popper.is-dark{
//   background: #255395;
// }
// .el-tooltip__popper[x-placement^=right] .popper__arrow::after{
//   border-right-color: #255395
// }
</style>
