"use strict";

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.getToken = getToken, exports.AmosFetch = exports.default = void 0;
var _amosProcessor = require("amos-processor"),
  utils = _interopRequireWildcard(require("amos-processor/lib/utils")),
  _AmosEnum = _interopRequireDefault(require("amos-processor/lib/enum/AmosEnum")),
  permission = _interopRequireWildcard(require("amos-processor/lib/config/permission")),
  _amosTool = require("amos-tool"),
  _config = _interopRequireDefault(require("amos-processor/lib/config"));

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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

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

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

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

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var lsTool = _amosTool.Store.lsTool,
  defaultHeaders = function() {
    return window.isPluginsToAmos ? window.requestInfo.staticHeader : {
      appKey: "AMOS_IOT",
      product: "AMOS_IOT_WEB"
    }
  },
  _default = _objectSpread(_objectSpread({}, utils), {}, {
    AmosEnum: _AmosEnum.default
  }, permission);

function getToken() {
  return lsTool.read(_config.default.token)
}
exports.default = _default;
var AmosFetch = {
  _fetch: function(o) {
    return function(e, t, r) {
      if (!_amosProcessor.AmosFetch[o]) throw new Error("AmosFetch: ´íÎóµÄÇëÇó[".concat(o, "]"));
      t = _amosTool.utils.merge({
        headers: _objectSpread(_objectSpread({}, defaultHeaders()), {}, {
          token: getToken()
        })
      }, t);
      return _amosProcessor.AmosFetch[o](e, {
        params: t,
        data: r
      })
    }
  },
  get: function(e, t) {
    var r = 1 < arguments.length && void 0 !== t ? t : {},
      t = r.params,
      r = r.data;
    return AmosFetch._fetch("get")(e, t, r)
  },
  put: function(e, t) {
    var r = 1 < arguments.length && void 0 !== t ? t : {},
      t = r.params,
      r = r.data;
    return AmosFetch._fetch("put")(e, t, r)
  },
  post: function(e, t) {
    var r = 1 < arguments.length && void 0 !== t ? t : {},
      t = r.params,
      r = r.data;
    return AmosFetch._fetch("post")(e, t, r)
  },
  del: function(e, t) {
    var r = 1 < arguments.length && void 0 !== t ? t : {},
      t = r.params,
      r = r.data;
    return AmosFetch._fetch("del")(e, t, r)
  }
};
exports.AmosFetch = AmosFetch;
