import { ConfigService } from "../configService/index.mjs";
import { apiMutate } from "../utilities/useAxiosMutate.mjs";
import { useCatalogStore } from "../stores/catalogStore.mjs";
import { c } from "react-compiler-runtime";
import { useEffect, useState } from "react";
//#region src/hooks/usePromotedMethodEntities.js
const usePromotedMethodEntities = (apiCatalogId) => {
	const $ = c(12);
	const [data, setData] = useState(void 0);
	const [loading, setLoading] = useState(true);
	const [error, setError] = useState(void 0);
	const [promise, setPromise] = useState(void 0);
	const { setPromotedMethodEntitiesMap, promotedMethodEntitiesMap } = useCatalogStore();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = (e) => {
			setLoading(false);
			setError(e);
		};
		$[0] = t0;
	} else t0 = $[0];
	const setErrorState = t0;
	let t1;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = (response) => {
			setError(void 0);
			setLoading(false);
			setData(response);
		};
		$[1] = t1;
	} else t1 = $[1];
	const setSuccessState = t1;
	let t2;
	let t3;
	if ($[2] !== apiCatalogId || $[3] !== promotedMethodEntitiesMap || $[4] !== setPromotedMethodEntitiesMap) {
		t2 = () => {
			let isMounted = true;
			if (!apiCatalogId) return;
			if (promotedMethodEntitiesMap[apiCatalogId]) {
				setSuccessState(promotedMethodEntitiesMap[apiCatalogId]);
				return () => {
					isMounted = false;
				};
			}
			const p = apiMutate(ConfigService.integrationV1ApiUrl, `apiCatalog/${apiCatalogId}/promotedMethodEntities?productId=${ConfigService.config.UNITY_PRODUCT_ID}`, {});
			p.then((response_0) => {
				if (isMounted) {
					setSuccessState(response_0.data);
					setPromotedMethodEntitiesMap({ [apiCatalogId]: response_0.data });
				}
			}).catch(setErrorState);
			setPromise(p);
			return () => {
				isMounted = false;
			};
		};
		t3 = [
			apiCatalogId,
			promotedMethodEntitiesMap,
			setPromotedMethodEntitiesMap,
			setSuccessState
		];
		$[2] = apiCatalogId;
		$[3] = promotedMethodEntitiesMap;
		$[4] = setPromotedMethodEntitiesMap;
		$[5] = t2;
		$[6] = t3;
	} else {
		t2 = $[5];
		t3 = $[6];
	}
	useEffect(t2, t3);
	let t4;
	if ($[7] !== data || $[8] !== error || $[9] !== loading || $[10] !== promise) {
		t4 = {
			data,
			loading,
			error,
			promise
		};
		$[7] = data;
		$[8] = error;
		$[9] = loading;
		$[10] = promise;
		$[11] = t4;
	} else t4 = $[11];
	return t4;
};
//#endregion
export { usePromotedMethodEntities };

//# sourceMappingURL=usePromotedMethodEntities.mjs.map