import{r as f,f as g}from"./vendor-ClLR6ncd.js";import{s as E}from"./lodash-ZyeDnt0e.js";import{d,i as p,f as m,ar as h,E as y,aX as S}from"./index-OtVJl4GC.js";import{b}from"./model-C9Idzwgo.js";const x=f.createContext();function v(s,i){const{urlPrefix:a,invalidate:n}=f.useContext(x);return d(o=>p({method:o?"put":"delete",url:m(a,i,s)}),{onSuccess:()=>n(i)})}function O(s){const[i,a]=f.useState(!1),n=f.useCallback(()=>a(!1),[a]),o=f.useCallback(()=>a(!0),[a]),c=g(),r=d(({entityName:t,params:e={}})=>{const l=new URL(`${s}/${t}`,window.origin);for(const[u,w]of Object.entries(e))l.searchParams.append(u,w||"");return p({url:l.toString(),method:"put"})},{onSuccess:(t,{entityName:e})=>{n(),h.invalidateQueries(["admin",s]),c(m("/admin",s,e))}});return{isOpen:i,openInputs:o,hideInputs:n,mutation:r}}const Q=[{urlSuffix:"permissions",key:"permissions"},{urlSuffix:"access",key:"access"},{urlSuffix:"security-filters/allow",key:"allowFilters"},{urlSuffix:"security-filters/disallow",key:"disallowFilters"}];async function q(s,i,a,n){const{allowFilters:o,disallowFilters:c,...r}=Object.assign({[i]:s},...await Promise.all(n.map(async({urlSuffix:t,key:e})=>({[e]:await p({url:m(a,s,t)})}))));return{...r,access:r.access.map(({catalog:t,...e})=>({catalog:b(t),...e})),securityFilters:o.map(t=>({...t,filter:"allow"})).concat(c.map(t=>({...t,filter:"disallow"})))}}const L=s=>function(a){const{queryKey:n,queryFn:o}=s(a);return y(n,o)},U=(s,i)=>function(){var l;const{data:n,isLoading:o,isFetching:c,isSuccess:r,error:t}=y(["admin",i],async()=>E(await p({url:i}))),e=S((n||[]).map(s));return{data:r?e.map(({data:u})=>u):[],isFetching:r?e.some(({isFetching:u})=>u):c,isLoading:r?e.some(({isLoading:u})=>u):o,error:r?(l=e.find(({error:u})=>u))==null?void 0:l.error:t}};export{x as E,U as a,L as b,Q as c,v as d,q as f,O as u};
