'use client';
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),y=require("../provider/auth-provider.cjs"),p=require("../provider/config-provider.cjs");function z(){const e=y.useAuth(),{userType:r,features:i}=p.useConfig(),s=t.useMemo(()=>e.user?.id||null,[e.user]),o=t.useMemo(()=>e.user?.primaryEmailAddress||null,[e.user]),u=t.useMemo(()=>e.user&&(e.user.username||`${e.user.firstName||""} ${e.user.lastName||""}`.trim()||e.user.primaryEmailAddress)||null,[e.user]),a=t.useMemo(()=>e.activeOrganization?.id||null,[e.activeOrganization]),c=t.useMemo(()=>e.activeOrganization?.name||null,[e.activeOrganization]),g=t.useMemo(()=>!!e.activeOrganization,[e.activeOrganization]),d=t.useMemo(()=>!e.activeOrganization||!e.user?!1:e.organizationMemberships.some(n=>n.organization.id===e.activeOrganization?.id),[e.activeOrganization,e.user,e.organizationMemberships]),h=t.useMemo(()=>{if(!e.activeOrganization||!e.user)return!1;const n=e.organizationMemberships.find(l=>l.organization.id===e.activeOrganization?.id);return n?.role==="admin"||n?.role==="owner"},[e.activeOrganization,e.user,e.organizationMemberships]),m=t.useMemo(()=>e.isLoaded&&e.isSignedIn,[e.isLoaded,e.isSignedIn]),f=t.useMemo(()=>e.user?!e.user.emailVerified||i.mfa&&!e.user.mfaEnabled:!1,[e.user,i.mfa]),O=t.useMemo(()=>e.user?i.mfa&&!e.user.mfaEnabled:!1,[e.user,i.mfa]),A=t.useCallback(async n=>{if(n.strategy==="oauth"&&!i.oauth)throw new Error("OAuth authentication is not enabled for this organization");if(n.strategy==="passkey"&&!i.passkeys)throw new Error("Passkey authentication is not enabled for this organization");if(n.strategy==="sso"&&!i.sso)throw new Error("SSO authentication is not enabled for this organization");if(n.strategy==="magic_link"&&!i.magicLink)throw new Error("Magic link authentication is not enabled for this organization");return e.signIn(n)},[e.signIn,i]),v=t.useCallback(async n=>{if(!i.signUp)throw new Error("User registration is not enabled for this organization");return e.signUp(n)},[e.signUp,i]),b=t.useCallback(n=>{const l=n||window.location.href;try{return new URL(l).searchParams.get("email")}catch{return null}},[]),M=t.useCallback(n=>{const l=n||window.location.href;try{return new URL(l).searchParams.get("token")}catch{return null}},[]);return{isLoaded:e.isLoaded,isLoading:e.isLoading,isSignedIn:e.isSignedIn,user:e.user,session:e.session,organization:e.organization,organizationMemberships:e.organizationMemberships,activeOrganization:e.activeOrganization,error:e.error,signIn:A,signUp:v,signOut:e.signOut,resendVerification:e.resendVerification,verifyIdentity:e.verifyIdentity,requestPasswordReset:e.requestPasswordReset,resetPassword:e.resetPassword,validateToken:e.validateToken,extractEmailFromUrl:b,extractTokenFromUrl:M,createSession:e.createSession,setActive:e.setActive,setActiveOrganization:e.setActiveOrganization,switchOrganization:e.switchOrganization,updateUser:e.updateUser,deleteUser:e.deleteUser,reload:e.reload,userId:s,userEmail:o,userName:u,organizationId:a,organizationName:c,userType:r,hasOrganization:g,isOrganizationMember:d,isOrganizationAdmin:h,isAuthenticated:m,requiresVerification:f,requiresMFA:O}}function I(){const{isLoaded:e,isLoading:r,isSignedIn:i,user:s,session:o,organization:u,activeOrganization:a,error:c,userId:g,userEmail:d,userName:h,organizationId:m,organizationName:f,userType:O,hasOrganization:A,isOrganizationMember:v,isOrganizationAdmin:b,isAuthenticated:M,requiresVerification:n,requiresMFA:l}=z();return{isLoaded:e,isLoading:r,isSignedIn:i,user:s,session:o,organization:u,activeOrganization:a,error:c,userId:g,userEmail:d,userName:h,organizationId:m,organizationName:f,userType:O,hasOrganization:A,isOrganizationMember:v,isOrganizationAdmin:b,isAuthenticated:M,requiresVerification:n,requiresMFA:l}}function S(){const{signIn:e,signUp:r,signOut:i,createSession:s,setActive:o,setActiveOrganization:u,switchOrganization:a,updateUser:c,deleteUser:g,reload:d}=z();return{signIn:e,signUp:r,signOut:i,createSession:s,setActive:o,setActiveOrganization:u,switchOrganization:a,updateUser:c,deleteUser:g,reload:d}}function k(){const{organization:e,organizationMemberships:r,activeOrganization:i,organizationId:s,organizationName:o,hasOrganization:u,isOrganizationMember:a,isOrganizationAdmin:c,setActiveOrganization:g,switchOrganization:d}=z();return{organization:e,organizationMemberships:r,activeOrganization:i,organizationId:s,organizationName:o,hasOrganization:u,isOrganizationMember:a,isOrganizationAdmin:c,setActiveOrganization:g,switchOrganization:d}}function U(){const{isLoaded:e,isLoading:r,isSignedIn:i,isAuthenticated:s,requiresVerification:o,requiresMFA:u,error:a}=z();return{isLoaded:e,isLoading:r,isSignedIn:i,isAuthenticated:s,requiresVerification:o,requiresMFA:u,hasError:!!a,error:a,status:r?"loading":i?"signed-in":"signed-out"}}exports.useAuth=z;exports.useAuthActions=S;exports.useAuthOrganization=k;exports.useAuthState=I;exports.useAuthStatus=U;
//# sourceMappingURL=use-auth.cjs.map
