import { ApiClientEvents } from "../events/api-client-events.js";
import { eventBus } from "../services/eventEmitter.js";
import "../services/index.js";
import { useStudio } from "../providers/StudioProvider.js";
import { c } from "react/compiler-runtime";
import axios from "axios";
import { useMemo } from "react";
import { ApiV1AuthApi, ApiV1ConfigApi, ApiV1DashboardApi, ApiV1DocumentsApi, ApiV1NamespacesApi, ApiV1PipelinesApi, ApiV1ProcessorApi, ApiV1WorkflowsApi, ApiV1WorkspacesApi, Configuration } from "@loopstack/api-client";
function useApiClient() {
	let _ = c(24), { environment: v } = useStudio(), y = v.url, b, x, S, C, w, T, E, D, O;
	if (_[0] !== v.id || _[1] !== y) {
		let h = new Configuration({ baseOptions: {
			withCredentials: !0,
			headers: { "Content-Type": "application/json" }
		} }), g = axios.create();
		g.interceptors.response.use(_temp, (h) => (h.response?.status && [401, 403].includes(h.response.status) && eventBus.emit(ApiClientEvents.UNAUTHORIZED, v.id), h.code === "ERR_NETWORK" && (console.error("Connection refused - server may be down"), eventBus.emit(ApiClientEvents.ERR_NETWORK, v.id)), Promise.reject(h))), b = new ApiV1AuthApi(h, y, g), x = new ApiV1DashboardApi(h, y, g), S = new ApiV1ConfigApi(h, y, g), C = new ApiV1DocumentsApi(h, y, g), w = new ApiV1NamespacesApi(h, y, g), T = new ApiV1PipelinesApi(h, y, g), E = new ApiV1ProcessorApi(h, y, g), D = new ApiV1WorkflowsApi(h, y, g), O = new ApiV1WorkspacesApi(h, y, g), _[0] = v.id, _[1] = y, _[2] = b, _[3] = x, _[4] = S, _[5] = C, _[6] = w, _[7] = T, _[8] = E, _[9] = D, _[10] = O;
	} else b = _[2], x = _[3], S = _[4], C = _[5], w = _[6], T = _[7], E = _[8], D = _[9], O = _[10];
	let k;
	_[11] !== b || _[12] !== x || _[13] !== S || _[14] !== C || _[15] !== w || _[16] !== T || _[17] !== E || _[18] !== D || _[19] !== O ? (k = {
		ApiV1AuthApi: b,
		ApiV1DashboardApi: x,
		ApiV1ConfigApi: S,
		ApiV1DocumentsApi: C,
		ApiV1NamespacesApi: w,
		ApiV1PipelinesApi: T,
		ApiV1ProcessorApi: E,
		ApiV1WorkflowsApi: D,
		ApiV1WorkspacesApi: O
	}, _[11] = b, _[12] = x, _[13] = S, _[14] = C, _[15] = w, _[16] = T, _[17] = E, _[18] = D, _[19] = O, _[20] = k) : k = _[20];
	let A = k, j;
	return _[21] !== A || _[22] !== v.id ? (j = {
		envKey: v.id,
		api: A
	}, _[21] = A, _[22] = v.id, _[23] = j) : j = _[23], j;
}
function _temp(n) {
	return n;
}
export { useApiClient };
