import "regenerator-runtime/runtime";
import _asyncToGenerator from "/Users/maxilo/workspace/code/npm/maxilo-vue-bootstrap-component/node_modules/_@babel_runtime@7.0.0-beta.47@@babel/runtime/helpers/builtin/es6/asyncToGenerator";
exports.default = {
  data: function data() {
    return {
      running: false
    };
  },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    block: {
      default: true
    },
    title: {
      default: '正在处理您的请求',
      type: String
    }
  },
  mounted: function mounted() {
    this.$el.style.cssText = this.$el.style.cssText + ';display: none !important;';
  },
  watch: {
    running: function running() {
      if (this.running) {
        this.showTriggle && this.showTriggle();
      } else {
        this.hideTriggle && this.hideTriggle();
      }

      this.render();
      this.$emit('input', this.running);
    },
    value: {
      handler: function handler() {
        this.running = this.value;
      },
      immediate: true
    }
  },
  methods: {
    render: function render() {
      this.$el.style.cssText = this.$el.style.cssText + ';display: ' + (this.running ? 'flex !important;flex-wrap: wrap;' : 'none !important') + ';';
    },
    show: function show() {
      this.running = true;
    },
    hide: function hide() {
      this.running = false;
    },
    wait: function () {
      var _wait = _asyncToGenerator(
      /*#__PURE__*/
      regeneratorRuntime.mark(function _callee2(fn) {
        var _this = this;

        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                this.show();
                return _context2.abrupt("return", new Promise(
                /*#__PURE__*/
                function () {
                  var _ref = _asyncToGenerator(
                  /*#__PURE__*/
                  regeneratorRuntime.mark(function _callee(ok) {
                    var ds;
                    return regeneratorRuntime.wrap(function _callee$(_context) {
                      while (1) {
                        switch (_context.prev = _context.next) {
                          case 0:
                            _context.next = 2;
                            return fn();

                          case 2:
                            ds = _context.sent;

                            _this.hide();

                            ok(ds);

                          case 5:
                          case "end":
                            return _context.stop();
                        }
                      }
                    }, _callee, this);
                  }));

                  return function (_x2) {
                    return _ref.apply(this, arguments);
                  };
                }()));

              case 2:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      return function wait(_x) {
        return _wait.apply(this, arguments);
      };
    }()
  }
};