<!-- 侧边栏菜单item license by http://eleadmin.com -->
<template>
  <a-sub-menu v-if="haveChildren" :key="item.path" :popup-class-name="firstPopClass">
    <template v-if="item.meta.icon" #icon>
      <component :is="item.meta.icon"/>
    </template>
    <template #title>
      <span>{{ item.meta.title }}</span>
    </template>
    <template v-for="child in item.children">
      <ele-pro-sidebar-item v-if="!child.meta.hide" :key="child.path" :item="child"/>
    </template>
  </a-sub-menu>
  <a-menu-item v-else :key="item.path">
    <template v-if="item.meta.icon" #icon>
      <component :is="item.meta.icon"/>
    </template>
    <span>{{ item.meta.title }}</span>
    <a v-if="isUrl" :href="item.path" target="_blank"></a>
    <router-link v-else :to="item.path"></router-link>
  </a-menu-item>
</template>

<script>
import * as antIcons from '@ant-design/icons-vue';
import {isUrl} from '../../util.js';

export default {
  name: 'EleProSidebarItem',
  components: {...antIcons},
  props: {
    // item数据
    item: {
      type: Object,
      required: true
    },
    // 一级pop菜单class
    firstPopClass: String
  },
  computed: {
    /* 是否有子级 */
    haveChildren() {
      return !!(this.item.children && this.item.children.filter((d) => !d.meta.hide).length);
    },
    /* 是否是网址 */
    isUrl() {
      return isUrl(this.item.path);
    }
  }
}
</script>
