"use strict";

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

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

require("core-js/modules/web.dom.iterable");

var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));

var _vue = _interopRequireDefault(require("vue"));

var _message = _interopRequireDefault(require("./message"));

/*
 * @Author: lijianzhang
 * @Date: 2018-03-07 23:50:36
 * @Last Modified by: lijianzhang
 * @Last Modified time: 2018-12-16 13:01:59
 */
var MessageVue = _vue.default.extend(_message.default);

function message(options) {
  var vm = new MessageVue();
  (0, _assign.default)(vm, (0, _assign.default)({}, 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 function () {
    if (vm.visible) {
      vm.visible = false;
    }
  };
}

['alert', 'warn', 'success', 'info', 'trash'].forEach(function (key) {
  _message.default[key] = function (m, props) {
    return message((0, _assign.default)({
      message: m,
      width: '350px'
    }, props, {
      type: key
    }));
  };
});
var _default = _message.default;
exports.default = _default;
_vue.default.prototype.$message = _message.default;