<template>
  <li class="ai-menu-item-group">
    <div class="ai-menu-item-group__title" :style="{paddingLeft: levelPadding + 'px'}">
      <template v-if="!$slots.title">{{title}}</template>
      <slot v-else name="title"></slot>
    </div>
    <ul>
      <slot></slot>
    </ul>
  </li>
</template>
<script>
  export default {
    name: 'AiMenuItemGroup',

    componentName: 'AiMenuItemGroup',

    inject: ['rootMenu'],
    props: {
      title: {
        type: String
      }
    },
    data() {
      return {
        paddingLeft: 20
      };
    },
    computed: {
      levelPadding() {
        // 控制分组
        let padding = 10;
        let parent = this.$parent;
        if (this.rootMenu.collapse) return 10;
        while (parent && parent.$options.componentName !== 'AiMenu') {
          if (parent.$options.componentName === 'AiSubmenu') {
            padding += 20;
          }
          parent = parent.$parent;
        }
        return padding;
      }
    }
  };
</script>

