<template>
  <div class="menu-wrapper">
    <template v-for="item in routes">
      <el-submenu
        v-if="!item.hidden&&item.children"
        :index="item.name||item.path"
        :key="item.name"
      >
        <template slot="title">
          <img-icon
            v-if="item.meta&&item.meta.icon"
            :iconName="item.meta.icon"
          ></img-icon>
          <span v-if="item.meta&&item.meta.title">{{item.meta.title}}</span>
        </template>

        <template v-for="child in item.children">
          <template v-if="!child.hidden">
            <sidebar-item
              :is-nest="true"
              class="nest-menu"
              v-if="child.children&&child.children.length>0"
              :routes="[child]"
              :key="child.path"
            ></sidebar-item>

            <router-link
              v-else
              :to="item.path+'/'+child.path"
              :key="child.name"
            >
              <el-menu-item :index="item.path+'/'+child.path">
                <!-- <svg-icon
                v-if="child.meta&&child.meta.icon"
                :icon-class="child.meta.icon"
              ></svg-icon> -->
                <span v-if="child.meta&&child.meta.title">{{child.meta.title}}</span>
                <span class="menu-arrow"></span>
              </el-menu-item>
            </router-link>
          </template>
        </template>
      </el-submenu>
      <router-link
        v-else-if="!item.hidden"
        :key="item.name"
        :to="item.path"
      >
        <el-menu-item :index="item.path">
          <span v-if="item.meta&&item.meta.title">{{item.meta.title}}</span>
          <span class="menu-arrow"></span>
        </el-menu-item>
      </router-link>
    </template>
  </div>
</template>

<script>
export default {
  name: "SidebarItem",
  props: {
    routes: {
      type: Array
    },
    isNest: {
      type: Boolean,
      default: false
    }
  }
};
</script>

<style lang="scss">
.menu-wrapper {
  .el-submenu__title i {
    color: #fff;
    transform: rotate(-90deg);
  }
  .el-submenu.is-opened > .el-submenu__title .el-submenu__icon-arrow {
    transform: rotate(0deg);
  }
}
</style>
