import "core-js/modules/es6.function.name";
import _classCallCheck from "D:\\progress\\h5\\company\\stc-ui\\node_modules\\@babel\\runtime/helpers/esm/classCallCheck";
import _createClass from "D:\\progress\\h5\\company\\stc-ui\\node_modules\\@babel\\runtime/helpers/esm/createClass";
import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";

/* eslint-disable */
import Vue from "vue";
import Toast from "./index.vue";
var ToastExt = Vue.extend(Toast);
var domArr = [];
var privateHide = Symbol("privateHide");

var ToastClass =
/*#__PURE__*/
function () {
  function ToastClass() {
    _classCallCheck(this, ToastClass);

    this.dom = null;
    this.unwatch = null;
  }
  /**
   * @desc 显示toast，显示之前要先关闭之前的toast
   */


  _createClass(ToastClass, [{
    key: "show",
    value: function show() {
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
          _ref$mask = _ref.mask,
          mask = _ref$mask === void 0 ? true : _ref$mask,
          _ref$title = _ref.title,
          title = _ref$title === void 0 ? "" : _ref$title,
          _ref$icon = _ref.icon,
          icon = _ref$icon === void 0 ? "" : _ref$icon,
          _ref$duration = _ref.duration,
          duration = _ref$duration === void 0 ? 1500 : _ref$duration,
          _ref$success = _ref.success,
          _success = _ref$success === void 0 ? function () {} : _ref$success;

      this.hide();
      this.dom = new ToastExt({
        el: document.createElement("div"),
        propsData: {
          mask: mask,
          show: true,
          title: title,
          icon: icon,
          duration: duration
        },
        methods: {
          success: function success() {
            _success();
          }
        }
      });
      document.body.appendChild(this.dom.$el);
      domArr.push(this.dom); // 监听app的路由变化，发生切换路由就关闭掉弹框
      // this.unwatch = router.app.$watch("$route", (to, from) => {
      //   this.hide();
      // });
    }
  }, {
    key: "hide",
    value: function hide() {
      var _this = this;

      domArr.map(function (item) {
        return _this[privateHide](item);
      });
      domArr = [];
    }
  }, {
    key: privateHide,
    value: function value(dom) {
      dom.show = false; // 解除监听
      // this.unwatch && this.unwatch();
    }
  }]);

  return ToastClass;
}();

Toast.install = function (Vue) {
  Vue.component(Toast.name, Toast);
};

Vue.prototype.$Toast = new ToastClass();
export default Toast;