import "./index.css";
/* script */
//
//
//
//
//
//
import { createComponentName, componentMixin } from '../../utils/base';
import Event from 'eventemitter3';
const __vue_script__ = {
  name: createComponentName('menu'),
  mixins: [componentMixin],
  model: {
    prop: 'indexPath',
    event: 'change'
  },
  props: {
    defaultIndexPath: {
      type: Array,
      default: () => []
    },
    indexPath: {
      type: Array
    },
    trigger: {
      type: String,
      default: 'hover'
    },
    router: {
      type: Boolean,
      default: false
    }
  },

  provide() {
    this.menuBus = new Event();
    return {
      menuBus: this.menuBus,
      rootMenu: this
    };
  },

  data() {
    return {
      innerIndexPath: this.indexPath || this.defaultIndexPath
    };
  },

  computed: {
    activeIndexPath: {
      get() {
        return this.indexPath || this.innerIndexPath;
      },

      set(value) {
        this.$emit('change', value);
        this.innerIndexPath = value;
      }

    }
  },

  mounted() {
    this.menuBus.on('menu-item:select', this.onSelect);
  },

  destroyed() {
    this.menuBus.removeListener('menu-item:select', this.onSelect);
  },

  methods: {
    open(index) {
      this.menuBus.emit('sub-menu:toggle', index, true);
    },

    close(index) {
      this.menuBus.emit('sub-menu:toggle', index, false);
    },

    onSelect(index, indexPath) {
      this.activeIndexPath = indexPath;
      this.$emit('select', index, indexPath);
    }

  }
};
/* template */

var __vue_render__ = function () {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c("ul", {
    class: _vm.bem()
  }, [_vm._t("default")], 2);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = false;
/* component normalizer */

import __vue_normalize__ from '../../utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);