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

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

export default {
  name: "SidebarItem",
  components: {
    Item,
    AppLink
  },
  props: {
    // route object
    item: {
      type: Object,
      required: true
    },
    isNest: {
      type: Boolean,
      default: false
    },
    basePath: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      onlyOneChild: null
    };
  },

  methods: {
    resolvePath(routePath) {
      if (isExternal(routePath)) {
        return routePath;
      }
      if (isExternal(this.basePath)) {
        return this.basePath;
      }
      return path.resolve(this.basePath, routePath);
    }
  }
};
</script>
<style type="text/css" scoped="scoped">
.el-menu-item {
  font-size: 12px;
}
</style>
