import { useState, useEffect } from 'react';
import { apiMutate } from '../utilities/useAxiosMutate';
import { useLookupsStore } from '../stores/lookupsStore';
import { UdpEnums } from '../enums/unitySystemEnums';
import { ConfigService } from '../configService';
export const usePromotedLookupMethods = (apiCatalogId, productId = ConfigService.config.UNITY_PRODUCT_ID) => {
    const [data, setData] = useState(undefined);
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(undefined);
    const setLookupApiMethodId = useLookupsStore((state) => state.setLookupApiMethodId);
    const setErrorState = (e) => {
        setLoading(false);
        setError(e);
    };
    const setSuccessState = (response) => {
        setError(undefined);
        setLoading(false);
        setData(response);
    };
    useEffect(() => {
        if (!apiCatalogId)
            return;
        const p = apiMutate(ConfigService.integrationV1ApiUrl, `apicatalog/${apiCatalogId}/promotedMethodEntities/${UdpEnums.Udp_Lookup}/product/${productId}?compareSanitizedName=true`, {});
        p.then((response) => {
            setSuccessState(response.data);
            const baseGetDataUdpLookupMethod = response.data['unityBaseGetDataMethod'];
            const baseGetUdpLookupMethod = response.data['unityBaseGetMethod'];
            const apiMethodId = (baseGetDataUdpLookupMethod === null || baseGetDataUdpLookupMethod === void 0 ? void 0 : baseGetDataUdpLookupMethod.apiMethodId) ||
                (baseGetUdpLookupMethod === null || baseGetUdpLookupMethod === void 0 ? void 0 : baseGetUdpLookupMethod.apiMethodId);
            if (apiMethodId) {
                setLookupApiMethodId(apiMethodId);
            }
        }).catch(setErrorState);
    }, [apiCatalogId, setLookupApiMethodId, productId]);
    return { data, loading, error };
};
//# sourceMappingURL=usePromotedLookupMethods.js.map