var h=Object.defineProperty;var t=(e,o)=>h(e,"name",{value:o,configurable:!0});import{AbilityBuilder as w,createMongoAbility as g}from"@casl/ability";import{unpackRules as W}from"@casl/ability/extra";import{useAbility as B}from"@casl/react";import{createContext as G,useEffect as E,useState as M}from"react";import{createContext as v,use as R,useMemo as U}from"react";import{jsx as k}from"react/jsx-runtime";var d;(r=>{let e=v({});r.Provider=t(({isAuthenticated:i,isInitializing:A,logout:s,updateTokens:u,accessToken:a,user:c,userPromise:l,routes:b,loadingState:y,children:m})=>{let f=U(()=>({isAuthenticated:i,isInitializing:A,logout:s,updateTokens:u,accessToken:a,user:c,userPromise:l,routes:b,loadingState:y}),[i,A,s,u,a,c,l,b,y]);return k(e.Provider,{value:f,children:m})},"Provider"),r.useAuth=t(()=>R(e),"useAuth")})(d||(d={}));import{jsx as O}from"react/jsx-runtime";var n;(s=>{let e=t(()=>new w(g),"createAppAbilityBuilder"),o=e().build(),p=G({});({Consumer:s.Consumer}=p),s.Provider=t(({children:u})=>{let[a,c]=M(o),{user:l}=d.useAuth();return E(()=>{if(!l||!("aclRules"in l))return;let{can:b,build:y}=e(),m=l.aclRules;W(m).forEach(({action:C,subject:T,conditions:x})=>{b(C,T,x)}),c(y())},[l]),O(p.Provider,{value:a,children:u})},"Provider"),s.useAbility=t(()=>B(p),"useAbility")})(n||(n={}));import{createContext as N,use as I,useMemo as S}from"react";import{jsx as q}from"react/jsx-runtime";var P;(r=>{let e=N(null);r.Provider=t(({children:i,replace:A})=>{let s=S(()=>({replace:A}),[A]);return q(e,{value:s,children:i})},"Provider"),r.useRouter=t(()=>{let i=I(e);if(!i)throw new Error("useRouter must be used within an OpenApiRouter.Provider");return i},"useRouter")})(P||(P={}));var z=t(()=>({canUse:e,redirectTo:o="/",children:p})=>{let r=n.useAbility(),{replace:i}=P.useRouter();return r.can(e[0],e[1])?p:(i(o),null)},"createAclGuard");import{createContextualCan as D}from"@casl/react";import{jsx as J}from"react/jsx-runtime";var F=D(n.Consumer),H=t(({use:e,...o})=>{let[p,r]=e;return J(F,{...o,do:p,on:r})},"Can");export{n as AbilityContext,H as Can,z as createAclGuard};
