{"version":3,"file":"useRequestUriName.mjs","sources":["../../../lib/data-provider-interface/composables/useRequestUriName.ts"],"sourcesContent":["import { useStore } from \"vuex\";\nimport { useRuntimeEnv } from \"../../composables/useRuntimeEnv\";\nimport { getTranslationFor } from \"../../utils/helpers\";\nimport { MaybeRefOrGetter, toValue } from \"vue\";\nimport { useAsyncState } from \"@vueuse/core\";\nimport { useAutocomplete } from \"./aucotomplete\";\n\n/**\n * Fetches the name of a resource based on its URI, vocabulary, and property.\n */\nexport function useRequestUriName(options: {\n  res: MaybeRefOrGetter<string>;\n  voc: MaybeRefOrGetter<string>;\n  property: MaybeRefOrGetter<string>;\n  locale: MaybeRefOrGetter<string>;\n}) {\n  const {\n    res: _res,\n    voc: _voc,\n    property: _property,\n    locale: _locale,\n  } = options;\n\n  const envs = useRuntimeEnv();\n  const store = useStore();\n  const { requestResourceName } = useAutocomplete()\n\n  const request = useAsyncState(\n    async () => {\n      const res = toValue(_res);\n      const voc = toValue(_voc);\n      const property = toValue(_property);\n      const locale = _locale;\n\n      if (res != undefined) {\n        let vocMatch =\n          voc === \"iana-media-types\" || voc === \"spdx-checksum-algorithm\";\n\n        let name;\n\n        await requestResourceName({\n            voc: voc,\n            uri: res,\n            envs,\n          })\n          .then((response) => {\n            if (property === \"dcatde:politicalGeocodingURI\") {\n              if (response != undefined) {\n                let result = vocMatch\n                  ? response.data.result.results\n                      .filter((dataset: any) => dataset.resource === res)\n                      .map((dataset: any) =>\n                        getTranslationFor(\n                          dataset.alt_label,\n                          toValue(locale),\n                          []\n                        )\n                      )[0]\n                  : getTranslationFor(\n                      response.data.result.alt_label,\n                      toValue(locale),\n                      []\n                    );\n                name = result;\n              }\n            } else {\n              if (response != undefined) {\n                let result = vocMatch\n                  ? response.data.result.results\n                      .filter((dataset: any) => dataset.resource === res)\n                      .map((dataset: any) =>\n                        getTranslationFor(\n                          dataset.pref_label,\n                          toValue(locale),\n                          []\n                        )\n                      )[0]\n                  : getTranslationFor(\n                      response.data.result.pref_label,\n                      toValue(locale),\n                      []\n                    );\n                name = result;\n              }\n            }\n          });\n\n        return name;\n      }\n    },\n    undefined,\n    { immediate: false }\n  );\n\n  return {\n    ...request,\n  };\n}\n"],"names":["useRequestUriName","options","_res","_voc","_property","_locale","envs","useRuntimeEnv","useStore","requestResourceName","useAutocomplete","useAsyncState","res","toValue","voc","property","locale","vocMatch","name","response","dataset","getTranslationFor"],"mappings":";;;;;;AAUO,SAASA,EAAkBC,GAK/B;AACK,QAAA;AAAA,IACJ,KAAKC;AAAA,IACL,KAAKC;AAAA,IACL,UAAUC;AAAA,IACV,QAAQC;AAAA,EACN,IAAAJ,GAEEK,IAAOC;AACC,EAAAC,EAAS;AACjB,QAAA,EAAE,qBAAAC,MAAwBC;AAqEzB,SAAA;AAAA,IACL,GApEcC;AAAA,MACd,YAAY;AACJ,cAAAC,IAAMC,EAAQX,CAAI,GAClBY,IAAMD,EAAQV,CAAI,GAClBY,IAAWF,EAAQT,CAAS,GAC5BY,IAASX;AAEf,YAAIO,KAAO,MAAW;AAChB,cAAAK,IACFH,MAAQ,sBAAsBA,MAAQ,2BAEpCI;AAEJ,uBAAMT,EAAoB;AAAA,YACtB,KAAAK;AAAA,YACA,KAAKF;AAAA,YACL,MAAAN;AAAA,UAAA,CACD,EACA,KAAK,CAACa,MAAa;AAClB,YAAIJ,MAAa,iCACXI,KAAY,SAgBPD,IAfMD,IACTE,EAAS,KAAK,OAAO,QAClB,OAAO,CAACC,MAAiBA,EAAQ,aAAaR,CAAG,EACjD;AAAA,cAAI,CAACQ,MACJC;AAAA,gBACED,EAAQ;AAAA,gBACRP,EAAQG,CAAM;AAAA,gBACd,CAAC;AAAA,cACH;AAAA,YAAA,EACA,CAAC,IACLK;AAAA,cACEF,EAAS,KAAK,OAAO;AAAA,cACrBN,EAAQG,CAAM;AAAA,cACd,CAAC;AAAA,YAAA,KAKLG,KAAY,SAgBPD,IAfMD,IACTE,EAAS,KAAK,OAAO,QAClB,OAAO,CAACC,MAAiBA,EAA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