import { resetEnvMode } from '../../constants/key.mjs';
import { useGlobalConfig } from '../../hooks/base/useGlobalConfig/index.mjs';
import { isString } from '../../utils/src/is.mjs';
import { envConfigs } from '../../utils/src/http/createModes.mjs';
import { urlJoin } from '../../utils/src/http/url.mjs';

const resetAxiosBaseURL = (options) => {
  const { config, baseUrlEnvKey, serviceType } = options;
  if (!config.baseURL) {
    const importMetaEnv = useGlobalConfig("env");
    if (isString(importMetaEnv.value[baseUrlEnvKey])) {
      config.baseURL = importMetaEnv.value[baseUrlEnvKey];
      return;
    }
    if (importMetaEnv.value.DEV) {
      config.baseURL = serviceType;
      return;
    }
    const resetMode = importMetaEnv.value[resetEnvMode];
    if (resetMode && envConfigs[resetMode]) {
      config.baseURL = urlJoin(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);
    }
  );
};

export { resetAxiosBaseURL, resetBaseURLInterceptorsRequest };
//# sourceMappingURL=resetAxiosBaseUrl.mjs.map
