"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = _default;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _react = _interopRequireWildcard(require("react")), _amosProcessor = require("amos-processor");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var n = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var a in e) if ("default" !== a && Object.prototype.hasOwnProperty.call(e, a)) {
    var o = i ? Object.getOwnPropertyDescriptor(e, a) : null;
    o && (o.get || o.set) ? Object.defineProperty(n, a, o) : n[a] = e[a];
  }
  return n.default = e, r && r.set(e, n), n;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, n = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(n, arguments, i);
    } else r = n.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

function ownKeys(e, t) {
  var r = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    t && (n = n.filter((function(t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    }))), r.push.apply(r, n);
  }
  return r;
}

function _objectSpread(e) {
  for (var t = 1; t < arguments.length; t++) {
    var r = null != arguments[t] ? arguments[t] : {};
    t % 2 ? ownKeys(Object(r), !0).forEach((function(t) {
      (0, _defineProperty2.default)(e, t, r[t]);
    })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach((function(t) {
      Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
    }));
  }
  return e;
}

function _default(e, t) {
  var r = (0, _extends2.default)({}, {
    method: "get"
  }, t), n = r.url, i = r.method, a = r.data, o = _objectSpread({
    method: i
  }, r.params);
  "POST" !== i && "PUT" !== i || (o.body = JSON.stringify(a));
  var u = function(t) {
    (0, _inherits2.default)(i, t);
    var r = _createSuper(i);
    function i(e) {
      var t;
      return (0, _classCallCheck2.default)(this, i), t = r.call(this, e), (0, _defineProperty2.default)((0, 
      _assertThisInitialized2.default)(t), "reload", (function(e) {
        var r = {};
        e && (r = {
          body: e
        }), (0, _amosProcessor.amosRequest)(n, r).then((function(e) {
          return t.setState({
            dataList: e
          });
        }));
      })), t.state = {
        dataList: null
      }, t;
    }
    return (0, _createClass2.default)(i, [ {
      key: "componentWillMount",
      value: function() {
        var e = this;
        (0, _amosProcessor.amosRequest)(n, o).then((function(t) {
          return e.setState({
            dataList: t
          });
        }));
      }
    }, {
      key: "render",
      value: function() {
        var t = this.state.dataList;
        return _react.default.createElement(e, (0, _extends2.default)({
          dataList: t,
          reload: this.reload
        }, this.props));
      }
    } ]), i;
  }(_react.Component);
  return u.displayName = "FetchComponent", u;
}