'use strict';

var key = require('../../constants/key.js');
var index = require('../../hooks/base/useGlobalConfig/index.js');
var is = require('../../utils/src/is.js');
var createModes = require('../../utils/src/http/createModes.js');
var url = require('../../utils/src/http/url.js');

const resetAxiosBaseURL = (options) => {
  const { config, baseUrlEnvKey, serviceType } = options;
  if (!config.baseURL) {
    const importMetaEnv = index.useGlobalConfig("env");
    if (is.isString(importMetaEnv.value[baseUrlEnvKey])) {
      config.baseURL = importMetaEnv.value[baseUrlEnvKey];
      return;
    }
    if (importMetaEnv.value.DEV) {
      config.baseURL = serviceType;
      return;
    }
    const resetMode = importMetaEnv.value[key.resetEnvMode];
    if (resetMode && createModes.envConfigs[resetMode]) {
      config.baseURL = url.urlJoin(createModes.envConfigs[resetMode].url, serviceType);
      return;
    }
    config.baseURL = serviceType;
  }
};
const resetBaseURLInterceptorsRequest = (service, options) => {
  service.interceptors.request.use(
    (config) => {
      resetAxiosBaseURL({ ...options, config });
      return config;
    },
    (error) => {
      console.error("\u8BF7\u6C42\u9519\u8BEF", error);
      return Promise.reject(error);
    }
  );
};

exports.resetAxiosBaseURL = resetAxiosBaseURL;
exports.resetBaseURLInterceptorsRequest = resetBaseURLInterceptorsRequest;
//# sourceMappingURL=resetAxiosBaseUrl.js.map
