"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),W=require("./use-auth.cjs");function h(){const{user:e,updateUser:m,deleteUser:c,reload:o,sdk:t}=W.useAuth(),[f,s]=r.useState(!1),[d,l]=r.useState(null),n=r.useCallback(a=>{const i={code:a.code||"UNKNOWN_ERROR",message:a.message||"An unknown error occurred",details:a.details,field:a.field};throw l(i),i},[]),u=r.useCallback(async a=>{if(!t.user)throw new Error("User not authenticated");try{s(!0),l(null);const i=await t.user.updateProfile(a);return await o(),i}catch(i){return n(i)}finally{s(!1)}},[t.user,o,n]),y=r.useCallback(async a=>{if(!t.user)throw new Error("User not authenticated");try{s(!0),l(null),await t.user.changePassword(a)}catch(i){n(i)}finally{s(!1)}},[t.user,n]),p=r.useCallback(async()=>{try{s(!0),l(null),await c()}catch(a){n(a)}finally{s(!1)}},[c,n]),P=r.useCallback(async a=>{try{s(!0),l(null),await u({primaryEmailAddress:a})}catch(i){n(i)}finally{s(!1)}},[u,n]),w=r.useCallback(async a=>{if(!t.user)throw new Error("User not authenticated");try{s(!0),l(null);const i={code:a,type:"email"};await t.auth.verifyEmail(i),await o()}catch(i){n(i)}finally{s(!1)}},[t.user,o,n]),E=r.useCallback(async()=>{if(!t.user||!e?.primaryEmailAddress)throw new Error("User not authenticated");try{s(!0),l(null),await t.user.resendEmailVerification(e.primaryEmailAddress)}catch(a){n(a)}finally{s(!1)}},[t.user,e?.primaryEmailAddress,n]),g=r.useCallback(async a=>{try{s(!0),l(null),await u({primaryPhoneNumber:a})}catch(i){n(i)}finally{s(!1)}},[u,n]),U=r.useCallback(async a=>{if(!t.user)throw new Error("User not authenticated");try{s(!0),l(null);const i={code:a,type:"phone"};await t.auth.verifyPhone(i),await o()}catch(i){n(i)}finally{s(!1)}},[t.user,o,n]),V=r.useCallback(async()=>{if(!t.user||!e?.primaryPhoneNumber)throw new Error("User not authenticated");try{s(!0),l(null),await t.user.resendPhoneVerification(e.primaryPhoneNumber)}catch(a){n(a)}finally{s(!1)}},[t.user,e?.primaryPhoneNumber,n]),b=r.useCallback(async a=>u({profileImageUrl:a}),[u]),A=r.useCallback(async()=>u({profileImageUrl:(void 0)()}),[u]),M=r.useCallback(async a=>u({unsafeMetadata:a}),[u]),N=r.useMemo(()=>e?.firstName||null,[e]),k=r.useMemo(()=>e?.lastName||null,[e]),v=r.useMemo(()=>{if(!e)return null;const a=[e.firstName,e.lastName].filter(Boolean);return a.length>0?a.join(" "):null},[e]),I=r.useMemo(()=>e?.primaryEmailAddress||null,[e]),C=r.useMemo(()=>e?.primaryPhoneNumber||null,[e]),S=r.useMemo(()=>e?.profileImageUrl||null,[e]),R=r.useMemo(()=>e?.username||null,[e]),L=r.useMemo(()=>e?.emailVerified||!1,[e]),q=r.useMemo(()=>e?.phoneVerified||!1,[e]),B=r.useMemo(()=>!!e&&!e.emailVerified,[e]),O=r.useMemo(()=>!!e&&!!e.primaryPhoneNumber&&!e.phoneVerified,[e]),j=r.useMemo(()=>e?.active||!1,[e]),D=r.useMemo(()=>e?.blocked||!1,[e]),K=r.useMemo(()=>e?.createdAt?new Date(e.createdAt):null,[e]),T=r.useMemo(()=>e?.lastSignInAt?new Date(e.lastSignInAt):null,[e]);return{user:e,isLoaded:!!e,isLoading:f,error:d,updateProfile:u,changePassword:y,deleteAccount:p,updateEmail:P,verifyEmail:w,resendEmailVerification:E,updatePhone:g,verifyPhone:U,resendPhoneVerification:V,updateProfileImage:b,removeProfileImage:A,updateMetadata:M,firstName:N,lastName:k,fullName:v,email:I,phone:C,profileImageUrl:S,username:R,isEmailVerified:L,isPhoneVerified:q,needsEmailVerification:B,needsPhoneVerification:O,isActive:j,isBlocked:D,createdAt:K,lastSignInAt:T}}function _(){const{user:e,firstName:m,lastName:c,fullName:o,email:t,phone:f,profileImageUrl:s,username:d,isEmailVerified:l,isPhoneVerified:n,isActive:u,isBlocked:y,createdAt:p,lastSignInAt:P}=h();return{user:e,firstName:m,lastName:c,fullName:o,email:t,phone:f,profileImageUrl:s,username:d,isEmailVerified:l,isPhoneVerified:n,isActive:u,isBlocked:y,createdAt:p,lastSignInAt:P}}function x(){const{isEmailVerified:e,isPhoneVerified:m,needsEmailVerification:c,needsPhoneVerification:o,verifyEmail:t,verifyPhone:f,resendEmailVerification:s,resendPhoneVerification:d,isLoading:l,error:n}=h();return{isEmailVerified:e,isPhoneVerified:m,needsEmailVerification:c,needsPhoneVerification:o,verifyEmail:t,verifyPhone:f,resendEmailVerification:s,resendPhoneVerification:d,isLoading:l,error:n,needsVerification:c||o}}function z(){const{updateProfile:e,changePassword:m,deleteAccount:c,updateEmail:o,updatePhone:t,updateProfileImage:f,removeProfileImage:s,updateMetadata:d,isLoading:l,error:n}=h();return{updateProfile:e,changePassword:m,deleteAccount:c,updateEmail:o,updatePhone:t,updateProfileImage:f,removeProfileImage:s,updateMetadata:d,isLoading:l,error:n}}exports.useUser=h;exports.useUserActions=z;exports.useUserProfile=_;exports.useUserVerification=x;
//# sourceMappingURL=use-user.cjs.map
