{"version":3,"file":"usePromotedLookupMethods.mjs","names":["useState","useEffect","apiMutate","fetchConfigOnce","useLookupsStore","UdpEnums","ConfigService","usePromotedLookupMethods","apiCatalogId","t0","$","_c","productId","undefined","config","UNITY_PRODUCT_ID","data","setData","loading","setLoading","error","setError","setLookupApiMethodId","_temp","t1","Symbol","for","e","setErrorState","t2","response","setSuccessState","t3","t4","url","Udp_Lookup","p","integrationV1ApiUrl","then","response_0","baseGetDataUdpLookupMethod","unityBaseGetDataMethod","baseGetUdpLookupMethod","unityBaseGetMethod","apiMethodId","catch","t5","state"],"sources":["../../src/hooks/usePromotedLookupMethods.js"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { apiMutate } from '../utilities/useAxiosMutate';\nimport { fetchConfigOnce } from '../utilities/configRequestDedupe';\nimport { useLookupsStore } from '../stores/lookupsStore';\nimport { UdpEnums } from '../enums/unitySystemEnums';\nimport { ConfigService } from '../configService';\n\nexport const usePromotedLookupMethods = (\n  apiCatalogId,\n  productId = ConfigService.config.UNITY_PRODUCT_ID\n) => {\n  const [data, setData] = useState(undefined);\n  const [loading, setLoading] = useState(true);\n  const [error, setError] = useState(undefined);\n  const setLookupApiMethodId = useLookupsStore(\n    (state) => state.setLookupApiMethodId\n  );\n\n  const setErrorState = (e) => {\n    setLoading(false);\n    setError(e);\n  };\n\n  const setSuccessState = (response) => {\n    setError(undefined);\n    setLoading(false);\n    setData(response);\n  };\n\n  useEffect(() => {\n    if (!apiCatalogId) return;\n\n    const url = `apicatalog/${apiCatalogId}/promotedMethodEntities/${UdpEnums.Udp_Lookup}/product/${productId}?compareSanitizedName=true`;\n\n    // Config read: fetched once per session and shared by every consumer.\n    const p = fetchConfigOnce(url, () =>\n      apiMutate(ConfigService.integrationV1ApiUrl, url, {})\n    );\n    p.then((response) => {\n      setSuccessState(response.data);\n      const baseGetDataUdpLookupMethod =\n        response.data['unityBaseGetDataMethod'];\n      const baseGetUdpLookupMethod = response.data['unityBaseGetMethod'];\n      const apiMethodId =\n        baseGetDataUdpLookupMethod?.apiMethodId ||\n        baseGetUdpLookupMethod?.apiMethodId;\n      if (apiMethodId) {\n        setLookupApiMethodId(apiMethodId);\n      }\n    }).catch(setErrorState);\n  }, [apiCatalogId, setLookupApiMethodId, productId]);\n\n  return { data, loading, error };\n};\n"],"mappings":";;;;;;;;AAOA,MAAaO,4BAA2BC,cAAAC,OAAA;CAAA,MAAAC,IAAAC,EAAA,GAAA;CAEtC,MAAAC,YAAAH,OAAAI,KAAAA,IAAYP,cAAaQ,OAAOC,mBAAhCN;CAEA,MAAA,CAAAO,MAAAC,WAAwBjB,SAASa,KAAAA,EAAU;CAC3C,MAAA,CAAAK,SAAAC,cAA8BnB,SAAS,KAAK;CAC5C,MAAA,CAAAoB,OAAAC,YAA0BrB,SAASa,KAAAA,EAAU;CAC7C,MAAAS,uBAA6BlB,gBAC3BmB,MACD;CAAC,IAAAC;AAAA,KAAAd,EAAA,OAAAe,OAAAC,IAAA,4BAAA,EAAA;AAEoBF,QAAAG,MAAA;AACpBR,cAAW,MAAM;AACjBE,YAASM,EAAE;;AACZjB,IAAA,KAAAc;OAAAA,MAAAd,EAAA;CAHD,MAAAkB,gBAAsBJ;CAGpB,IAAAK;AAAA,KAAAnB,EAAA,OAAAe,OAAAC,IAAA,4BAAA,EAAA;AAEsBG,QAAAC,aAAA;AACtBT,YAASR,KAAAA,EAAU;AACnBM,cAAW,MAAM;AACjBF,WAAQa,SAAS;;AAClBpB,IAAA,KAAAmB;OAAAA,MAAAnB,EAAA;CAJD,MAAAqB,kBAAwBF;CAItB,IAAAG;CAAA,IAAAC;AAAA,KAAAvB,EAAA,OAAAF,gBAAAE,EAAA,OAAAE,aAAAF,EAAA,OAAAY,sBAAA;AAEQU,aAAA;AACR,OAAI,CAACxB,aAAY;GAEjB,MAAA0B,MAAY,cAAc1B,aAAY,0BAA2BH,SAAQ8B,WAAW,WAAYvB,UAAS;AAG/FT,mBAAgB+B,WACxBhC,UAAUI,cAAa+B,qBAAsBH,K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