import "./sub-menu.css";
/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import { createComponentName, componentMixin } from '../../utils/base';
import createCollapseTransition from '../../utils/collapse-transition';
import MenuItem from './item';
import Popover from '../popover';
const __vue_script__ = {
  name: createComponentName('sub-menu'),
  components: {
    Popover
  },
  mixins: [componentMixin],
  inject: ['menuBus', 'rootMenu'],
  props: {
    title: {
      type: String
    },
    index: {
      type: [String, Number],
      required: true
    },
    route: {
      type: String
    },
    hideMenu: {
      type: Boolean,
      default: false
    },
    offset: {
      type: String,
      default: '0'
    },
    placement: {
      type: String,
      default: 'bottom'
    },
    popoverClass: {
      type: String
    }
  },

  data() {
    return {
      MenuItem
    };
  },

  beforeCreate() {
    this.collapseTransition = createCollapseTransition();
  },

  mounted() {
    this.menuBus.on('sub-menu:toggle', this.onToggle);
  },

  destroyed() {
    this.menuBus.removeListener('sub-menu:toggle', this.onToggle);
  },

  methods: {
    onToggle(index, toggle) {
      if (this.index === index && this.$refs.popover) {
        this.$refs.popover.isShowPopper = toggle;
      }
    },

    close() {
      this.$refs.popover.isShowPopper = false;
    }

  }
};
/* template */

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

  var _h = _vm.$createElement;

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

  return _c("Popover", _vm._g(_vm._b({
    ref: "popover",
    attrs: {
      tag: _vm.MenuItem,
      "transition-on": _vm.collapseTransition,
      trigger: _vm.rootMenu.trigger,
      index: _vm.index,
      route: _vm.route,
      lazy: false,
      "popover-class": [_vm.bem("popover"), _vm.popoverClass],
      placement: _vm.placement,
      modifiers: {
        offset: {
          offset: _vm.offset
        }
      }
    }
  }, "Popover", _vm.$attrs, false), _vm.$listeners), [_vm._t("title", [_vm._v(_vm._s(_vm.title))]), _vm._v(" "), !_vm.hideMenu ? _c("ul", {
    class: _vm.bem(),
    attrs: {
      slot: "popup"
    },
    slot: "popup"
  }, [_vm._t("default")], 2) : _vm._e()], 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);