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";

var adapter = function adapter() {
  this.name = 'mxl_bootstrap_component_adapter';
  this.adapters = {
    alias: {},
    responseFormat: function responseFormat(ds) {
      return ds;
    }
  };
  this.useAlert = false;
  this.adapterInstance = [];
  /* alias: component level */

  /* responseFormat: component with http module */

  this.merge = function (key, options) {
    if (!this.adapters[key]) {
      return;
    }

    if (this.app.utils.base.getType(options) == 'Function' && this.app.utils.base.getType(this.adapters[key]) == 'Function') {
      this.adapters[key] = options;
      return;
    }

    this.adapters[key] = this.app.utils._.merge(this.adapters[key], options);
  };

  this.add = function (obj) {
    if (this.app.utils.base.getType(obj) != 'Object') {
      return;
    }

    this.adapterInstance.push(obj);
  };

  this.run =
  /*#__PURE__*/
  function () {
    var _ref = _asyncToGenerator(
    /*#__PURE__*/
    regeneratorRuntime.mark(function _callee(vue) {
      var _this = this;

      var len, i, v, alias, _tmp;

      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              len = this.adapterInstance.length;

              for (i = 0; i < len; i++) {
                v = this.adapterInstance[i];

                if (v.alias) {
                  alias = v.alias();
                  _tmp = this.app.utils.base.getType(alias);

                  if (_tmp != 'Object') {
                    console.log('[mxl-bootstrap-component - adapter warning] alias return ' + _tmp + ' qipan(:>) Object.');
                  } else {
                    this.merge('alias', alias);
                  }
                }

                if (v.responseFormat) {
                  if (this.app.utils.base.getType(v.responseFormat) != 'Function') {
                    console.log('[mxl-bootstrap-component - adapter warning] responseFormat is ' + tmp + ' qipan(:>) Function.');
                  } else {
                    this.merge('responseFormat', v);
                  }
                }
              }

              Object.defineProperty(vue.prototype, '$mxl_bootstrap_component_adapter', {
                get: function get() {
                  return _this.adapters;
                }
              });

              if (!this.useAlert) {
                _context.next = 7;
                break;
              }

              _context.next = 6;
              return import('sweetalert');

            case 6:
              this.app.alert.base = _context.sent;

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

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

export default adapter;