"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

require("./index.css");

var _component = require("../_utils/component");

var _eventemitter = _interopRequireDefault(require("eventemitter3"));

var _vueNormalizeComponent = _interopRequireDefault(require("../_utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
var __vue_script__ = {
  name: (0, _component.createComponentName)('menu'),
  mixins: [_component.componentMixin],
  model: {
    prop: 'indexPath',
    event: 'change'
  },
  props: {
    defaultIndexPath: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    indexPath: {
      type: Array
    },
    trigger: {
      type: String,
      default: 'hover'
    },
    router: {
      type: Boolean,
      default: false
    }
  },

  provide() {
    this.menuBus = new _eventemitter.default();
    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 __vue_render__() {
  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 */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default2 = (0, _vueNormalizeComponent.default)({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default2;