/*
 * @Description:
 * @Version: 2.0
 * @Autor: mayako
 * @Date: 2020-01-15 18:18:16
 * @LastEditors  : mayako
 * @LastEditTime : 2020-01-15 18:54:25
 */
export default {
  inject: ['rootMenu'],
  computed: {
    indexPath() {
      const path = [this.index];
      let parent = this.$parent;
      while (parent.$options.componentName !== 'ElMenu') {
        if (parent.index) {
          path.unshift(parent.index);
        }
        parent = parent.$parent;
      }
      return path;
    },
    parentMenu() {
      let parent = this.$parent;
      while (
        parent && ['ElMenu', 'ElSubmenu'].indexOf(parent.$options.componentName) === -1
      ) {
        parent = parent.$parent;
      }
      return parent;
    },
    paddingStyle() {
      if (this.rootMenu.mode !== 'vertical') return {};

      let padding = 25;
      let parent = this.$parent;

      if (this.rootMenu.collapse) {
        padding = 25;
      } else {
        while (parent && parent.$options.componentName !== 'ElMenu') {
          if (parent.$options.componentName === 'ElSubmenu') {
            padding += 25;
          }
          parent = parent.$parent;
        }
      }
      return {
        paddingLeft: padding + 'px'
      };
    }
  }
};
