"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _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 ownKeys(e, r) {
    var t = Object.keys(e);
    if (Object.getOwnPropertySymbols) {
        var o = Object.getOwnPropertySymbols(e);
        r && (o = o.filter((function(r) {
            return Object.getOwnPropertyDescriptor(e, r).enumerable;
        }))), t.push.apply(t, o);
    }
    return t;
}

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

var lsTool = _amosTool.Store.lsTool, defaultHeaders = function() {
    return window.isIotPluginsToAmos ? window.iotRequestInfo.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(e) {
        return function(r, t, o) {
            if (!_amosProcessor.AmosFetch[e]) throw new Error("AmosFetch: ´íÎóµÄÇëÇó[".concat(e, "]"));
            var s = _amosTool.utils.merge({
                headers: _objectSpread(_objectSpread({}, defaultHeaders()), {}, {
                    token: getToken()
                })
            }, t);
            return _amosProcessor.AmosFetch[e](r, {
                params: s,
                data: o
            });
        };
    },
    get: function(e) {
        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
        return AmosFetch._fetch("get")(e, t, o);
    },
    put: function(e) {
        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
        return AmosFetch._fetch("put")(e, t, o);
    },
    post: function(e) {
        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
        return AmosFetch._fetch("post")(e, t, o);
    },
    del: function(e) {
        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
        return AmosFetch._fetch("del")(e, t, o);
    }
};

exports.AmosFetch = AmosFetch;