"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _context = require("@arcblock/ux/lib/Locale/context");
var _jsSdk = require("@blocklet/js-sdk");
var _isNull = _interopRequireDefault(require("lodash/isNull"));
var _util = require("./util");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const api = (0, _jsSdk.createAxios)();
api.interceptors.request.use(config => {
  const prefix = (0, _util.getPrefix)();
  config.baseURL = prefix || "";
  const locale = (0, _context.getLocale)(window.blocklet?.languages);
  const query = new URLSearchParams(config.url?.split("?").pop());
  config.params = {
    ...(config.params || {}),
    locale
  };
  const authToken = window.__PAYMENT_KIT_AUTH_TOKEN;
  if (authToken && typeof config.params.authToken === "undefined" && !query.has("authToken")) {
    config.params.authToken = authToken;
  }
  if (typeof config.params.livemode === "undefined" && query.has("livemode") === false) {
    const livemode = localStorage.getItem("livemode");
    config.params.livemode = (0, _isNull.default)(livemode) ? true : JSON.parse(livemode);
  }
  return config;
}, err => Promise.reject(err));
module.exports = api;