import{useQuery as a}from"@tanstack/react-query";import{useMemo as c}from"react";import{withPathPrefix as u}from"@redocly/theme/core/utils";function f(t){return t.length>=2&&t.startsWith('"')&&t.endsWith('"')?t:`"${t}"`}function l({entityKey:t,version:e}){const r=a({queryFn:async()=>{const o=new URLSearchParams;o.append("filter",`catalogEntityKey:${f(t)}`),e&&o.append("version",e);const n=new URL(u("/bff/catalog-revisions"),window.location.origin);n.search=o.toString();const i=await fetch(n.toString());if(!i.ok)throw new Error(`Failed to fetch catalog entity revisions from ${n.pathname}`);return i.json()},queryKey:["bff/catalog-revisions",{entityKey:t,version:e}],refetchOnMount:!0}),s=c(()=>r.data?.items??[],[r.data?.items]);return{query:r,items:s}}export{l as useFetchCatalogEntityRevisions};
