import "core-js/modules/web.dom.iterable";
import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";

/*
 * @Author: lijianzhang
 * @Date: 2018-03-07 23:50:36
 * @Last Modified by: lijianzhang
 * @Last Modified time: 2018-12-16 13:01:59
 */
import Vue from 'vue';
import Message from './message';
const MessageVue = Vue.extend(Message);

function message(options) {
  const vm = new MessageVue();

  _Object$assign(vm, { ...options,

    onClose() {
      vm.$destroy();
      if (vm.$el && vm.$el.parentNode) vm.$el.parentNode.removeChild(vm.$el);
    }

  });

  vm.$mount();
  window.vm = vm;
  vm.visible = true;
  return () => {
    if (vm.visible) {
      vm.visible = false;
    }
  };
}

['alert', 'warn', 'success', 'info', 'trash'].forEach(key => {
  Message[key] = (m, props) => {
    return message({
      message: m,
      width: '350px',
      ...props,
      type: key
    });
  };
});
export default Message;
Vue.prototype.$message = Message;