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

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

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


  _createClass(ModalClass, [{
    key: "show",
    value: function show() {
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
          _ref$title = _ref.title,
          title = _ref$title === void 0 ? "" : _ref$title,
          _ref$content = _ref.content,
          content = _ref$content === void 0 ? "" : _ref$content,
          _ref$showCancel = _ref.showCancel,
          showCancel = _ref$showCancel === void 0 ? true : _ref$showCancel,
          _ref$cancelText = _ref.cancelText,
          cancelText = _ref$cancelText === void 0 ? "取消" : _ref$cancelText,
          _ref$confirmText = _ref.confirmText,
          confirmText = _ref$confirmText === void 0 ? "确定" : _ref$confirmText,
          _ref$confirmAutoHide = _ref.confirmAutoHide,
          confirmAutoHide = _ref$confirmAutoHide === void 0 ? true : _ref$confirmAutoHide,
          _ref$cancelAutoHide = _ref.cancelAutoHide,
          cancelAutoHide = _ref$cancelAutoHide === void 0 ? true : _ref$cancelAutoHide,
          _ref$success = _ref.success,
          _success = _ref$success === void 0 ? function () {} : _ref$success,
          _ref$fail = _ref.fail,
          _fail = _ref$fail === void 0 ? function () {} : _ref$fail,
          _ref$complete = _ref.complete,
          complete = _ref$complete === void 0 ? function () {} : _ref$complete;

      this.hide();
      this.dom = new ModalExt({
        el: document.createElement("div"),
        propsData: {
          show: true,
          title: title,
          content: content,
          showCancel: showCancel,
          cancelText: cancelText,
          confirmText: confirmText,
          confirmAutoHide: confirmAutoHide,
          cancelAutoHide: cancelAutoHide
        },
        methods: {
          success: function success(res) {
            _success(res);

            complete(res);
          },

          /**
           * @desc 不会存在fail所以这里不实现这个方法
           */
          fail: function fail() {
            _fail("nothing");

            complete("nothing");
          }
        }
      });
      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 ModalClass;
}();

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

Vue.prototype.$Modal = new ModalClass();
export default Modal;