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";
import vue from 'vue';
import ActionSheet from "./index.vue";
var ActionSheetExt = vue.extend(ActionSheet);
var domArr = [];
var privateHide = Symbol('privateHide');

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

    this.dom = null;
    this.unwatch = null;
  }

  _createClass(ActionSheetClass, [{
    key: "show",
    value: function show() {
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
          _ref$buttons = _ref.buttons,
          buttons = _ref$buttons === void 0 ? [] : _ref$buttons,
          _ref$title = _ref.title,
          title = _ref$title === void 0 ? '' : _ref$title,
          _ref$contentType = _ref.contentType,
          contentType = _ref$contentType === void 0 ? '1' : _ref$contentType;

      this.hide();
      this.dom = new ActionSheetExt({
        el: document.createElement('div'),
        propsData: {
          buttons: buttons,
          title: title,
          contentType: contentType
        }
      });
      document.body.appendChild(this.dom.$el);
      domArr.push(this.dom); // TODO: router这里没有这个玩意
      // const that = this;
      // 监听app的路由变化，发生切换路由就关闭掉弹框
      // that.unwatch = router.app.$watch('$route', (to, from) => {
      //   that.hide();
      //   if (that.dom !== undefined) {
      //     that.dom.$destroy();
      //     if (that.dom.$el.parentNode) {
      //       that.dom.$el.parentNode.removeChild(this.dom.$el);
      //     }
      //   }
      // });

      return this.dom.activate();
    }
  }, {
    key: "hide",
    value: function hide() {
      var _this = this;

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

      this.unwatch && this.unwatch();
    }
  }]);

  return ActionSheetClass;
}();

export default (function () {
  return vue.prototype.$ActionSheet = new ActionSheetClass();
});