import { ConfigService } from "../configService/index.mjs";
import { UdpEnums } from "../enums/unitySystemEnums.mjs";
import { apiMutate } from "../utilities/useAxiosMutate.mjs";
import { useLookupsStore } from "../stores/lookupsStore.mjs";
import { c } from "react-compiler-runtime";
import { useEffect, useState } from "react";
//#region src/hooks/usePromotedLookupMethods.js
const usePromotedLookupMethods = (apiCatalogId, t0) => {
	const $ = c(11);
	const productId = t0 === void 0 ? ConfigService.config.UNITY_PRODUCT_ID : t0;
	const [data, setData] = useState(void 0);
	const [loading, setLoading] = useState(true);
	const [error, setError] = useState(void 0);
	const setLookupApiMethodId = useLookupsStore(_temp);
	let t1;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = (e) => {
			setLoading(false);
			setError(e);
		};
		$[0] = t1;
	} else t1 = $[0];
	const setErrorState = t1;
	let t2;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t2 = (response) => {
			setError(void 0);
			setLoading(false);
			setData(response);
		};
		$[1] = t2;
	} else t2 = $[1];
	const setSuccessState = t2;
	let t3;
	let t4;
	if ($[2] !== apiCatalogId || $[3] !== productId || $[4] !== setLookupApiMethodId) {
		t3 = () => {
			if (!apiCatalogId) return;
			apiMutate(ConfigService.integrationV1ApiUrl, `apicatalog/${apiCatalogId}/promotedMethodEntities/${UdpEnums.Udp_Lookup}/product/${productId}?compareSanitizedName=true`, {}).then((response_0) => {
				setSuccessState(response_0.data);
				const baseGetDataUdpLookupMethod = response_0.data.unityBaseGetDataMethod;
				const baseGetUdpLookupMethod = response_0.data.unityBaseGetMethod;
				const apiMethodId = baseGetDataUdpLookupMethod?.apiMethodId || baseGetUdpLookupMethod?.apiMethodId;
				if (apiMethodId) setLookupApiMethodId(apiMethodId);
			}).catch(setErrorState);
		};
		t4 = [
			apiCatalogId,
			setLookupApiMethodId,
			productId
		];
		$[2] = apiCatalogId;
		$[3] = productId;
		$[4] = setLookupApiMethodId;
		$[5] = t3;
		$[6] = t4;
	} else {
		t3 = $[5];
		t4 = $[6];
	}
	useEffect(t3, t4);
	let t5;
	if ($[7] !== data || $[8] !== error || $[9] !== loading) {
		t5 = {
			data,
			loading,
			error
		};
		$[7] = data;
		$[8] = error;
		$[9] = loading;
		$[10] = t5;
	} else t5 = $[10];
	return t5;
};
function _temp(state) {
	return state.setLookupApiMethodId;
}
//#endregion
export { usePromotedLookupMethods };

//# sourceMappingURL=usePromotedLookupMethods.mjs.map