<template>
  <div class="menu-wrapper">
    <template v-for="item in routes" v-if="!item.hidden&&item.children">
      <!--一级-->
      <router-link v-if="item.children.length===1 && !item.children[0].children" :key="item.children[0].name" :to="item.path+'/'+item.children[0].path">
        <el-menu-item :index="item.path+'/'+item.children[0].path" :class="{'submenu-title-noDropdown':!isNest}">
          <svg-icon v-if="item.children[0].meta&&item.children[0].meta.icon" :icon-class="item.children[0].meta.icon"/>
          <span v-if="item.children[0].meta&&item.children[0].meta.title">{{ translateMenuTitle(item.children[0].meta.title) }}</span>
        </el-menu-item>
      </router-link>
      <!--二级-->
      <el-submenu v-else :key="item.name" :index="item.name||item.path">
        <template slot="title">
          <svg-icon v-if="item.meta&&item.meta.icon" :icon-class="item.meta.icon"/>
          <span v-if="item.meta&&item.meta.title">{{ translateMenuTitle(item.meta.title) }}</span>
        </template>

        <template v-for="child in item.children" v-if="!child.hidden">
          <sidebar-item v-if="child.children&&child.children.length>0" :key="child.path" :routes="[child]" :is-nest="true" class="nest-menu"/>
          <router-link v-else :key="child.name" :to="item.path+child.path">
            <el-menu-item :index="item.path+'/'+child.path">
              <svg-icon v-if="child.meta&&child.meta.icon" :icon-class="child.meta.icon"/>
              <span v-if="child.meta&&child.meta.title">{{ translateMenuTitle(child.meta.title) }}</span>
              {{ item.path+'/'+child.path }}
            </el-menu-item>
          </router-link>
        </template>
      </el-submenu>

    </template>
  </div>
</template>

<script>
import { translateMenuTitle } from '@/utils/i18n'

export default {
  name: 'SidebarItem',
  props: {
    routes: {
      type: Array,
      default: null
    },
    isNest: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    translateMenuTitle
  }
}
</script>
