"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index = require("../platform/index.js");
const utils = require("../utils.js");
const isURLSameOrigin = require("./isURLSameOrigin.js");
const cookies = require("./cookies.js");
const buildFullPath = require("../core/buildFullPath.js");
const mergeConfig = require("../core/mergeConfig.js");
const AxiosHeaders = require("../core/AxiosHeaders.js");
const buildURL = require("./buildURL.js");
const resolveConfig = (config) => {
  const newConfig = mergeConfig.default({}, config);
  let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
  newConfig.headers = headers = AxiosHeaders.default.from(headers);
  newConfig.url = buildURL.default(buildFullPath.default(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
  if (auth) {
    headers.set(
      "Authorization",
      "Basic " + btoa((auth.username || "") + ":" + (auth.password ? unescape(encodeURIComponent(auth.password)) : ""))
    );
  }
  let contentType;
  if (utils.default.isFormData(data)) {
    if (index.default.hasStandardBrowserEnv || index.default.hasStandardBrowserWebWorkerEnv) {
      headers.setContentType(void 0);
    } else if ((contentType = headers.getContentType()) !== false) {
      const [type, ...tokens] = contentType ? contentType.split(";").map((token) => token.trim()).filter(Boolean) : [];
      headers.setContentType([type || "multipart/form-data", ...tokens].join("; "));
    }
  }
  if (index.default.hasStandardBrowserEnv) {
    withXSRFToken && utils.default.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
    if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin.default(newConfig.url)) {
      const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.default.read(xsrfCookieName);
      if (xsrfValue) {
        headers.set(xsrfHeaderName, xsrfValue);
      }
    }
  }
  return newConfig;
};
exports.default = resolveConfig;
