import { getAccessToken, getMergedConfig, handleResponseErrors } from "./apiHelpers.mjs";
import axiosInterceptors from "./axiosInterceptors.mjs";
import { useUser } from "./auth/useUser.mjs";
import { useEffect, useMemo } from "react";
import useAxios from "axios-hooks";
import Axios from "axios";
//#region src/utilities/useAxiosMutate.js
axiosInterceptors();
const useAxiosMutate = (baseURL, url, config) => {
	const fullURL = { url: `${baseURL}/${url}` };
	const user = useUser();
	config.headers = useMemo(() => {
		const currentHeaders = config.headers ?? {};
		currentHeaders.currentTenantId ||= user?.currentTenantId ?? "";
		return currentHeaders;
	}, [user, config]);
	const [{ data, loading, error }, execute] = useAxios({
		...fullURL,
		...config
	}, { manual: true });
	useEffect(() => {
		handleResponseErrors(error);
	}, [error]);
	return [{
		data,
		loading,
		error
	}, execute];
};
const apiMutate = async (baseURL, url, config, data) => {
	const fullURL = { url: `${baseURL}/${url}` };
	const mergedConfig = getMergedConfig(await getAccessToken(), config);
	return Axios({
		...fullURL,
		...mergedConfig,
		...data
	});
};
//#endregion
export { apiMutate, useAxiosMutate };

//# sourceMappingURL=useAxiosMutate.mjs.map