import { languageStore, Language } from "@shared";
import axios from "axios";

const authInstance = axios.create({
  baseURL: "https://wn.krbl.ru",
});

authInstance.interceptors.request.use((config) => {
  config.headers.Authorization = `Bearer ${localStorage.getItem("token")}`;
  config.headers["X-Language"] = languageStore.language ?? "ru";
  return config;
});

const languageInstance = (language: Language) => {
  const instance = axios.create({
    baseURL: "https://wn.krbl.ru",
  });
  instance.interceptors.request.use((config) => {
    config.headers.Authorization = `Bearer ${localStorage.getItem("token")}`;
    config.headers["X-Language"] = language;
    return config;
  });
  return instance;
};

export { authInstance, languageInstance };
