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 LoadingComponent from "./index.vue";
import config from "./config";
var LoadingExt = Vue.extend(LoadingComponent);
var domArr = [];
var privateHide = Symbol("privateHide");

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

    this.dom = null;
    this.unwatch = null;
  }
  /**
   * 显示
   */


  _createClass(LoadingClass, [{
    key: "show",
    value: function show() {
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
          mask = _ref.mask,
          icon = _ref.icon,
          text = _ref.text;

      this.hide();
      this.dom = new LoadingExt({
        el: document.createElement("div"),
        propsData: {
          show: true,
          mask: mask,
          icon: icon,
          text: text
        }
      });
      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 LoadingClass;
}();

var Loading = new LoadingClass();
Object.defineProperty(Loading, "install", {
  configurable: false,
  enumerable: false,
  value: function value(Vue, options) {
    // 重载默认配置
    Object.assign(config.props, options && options.props);
    Vue.prototype.$Loading = Loading;
  }
}); // Loading.install = Vue => {
//   Vue.component(Loading.name, Loading);
// };

export default Loading;