<template>
  <li class="xb-menu-item-group">
    <div class="xb-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: 'XbMenuItemGroup',

    componentName: 'XbMenuItemGroup',

    inject: ['rootMenu'],
    props: {
      title: {
        type: String
      }
    },
    data() {
      return {
        paddingLeft: 25
      };
    },
    computed: {
      levelPadding() {
        let padding = 25;
        let parent = this.$parent;
        if (this.rootMenu.collapse) return 25;
        while (parent && parent.$options.componentName !== 'XbMenu') {
          if (parent.$options.componentName === 'XbSubmenu') {
            padding += 25;
          }
          parent = parent.$parent;
        }
        return padding;
      }
    }
  };
</script>

