import{l as n,m as o,a as U,o as C,a9 as y,p as u,n as S,t as i,R as c,q as I}from"./index-C-gKvEDq.js";import{q as g}from"./query-keys-DGBjVswC.js";import{o as d,s as t}from"./schemas-IctYPUjJ.js";const a={login:async s=>{const{data:r}=await n.post(o.LOGIN,s);return r.data},logout:async()=>{await n.post(o.LOGOUT)},getCurrentUser:async()=>{const{data:s}=await n.get(o.USER_ME);return s.data},changePassword:async s=>{await n.post(o.CHANGE_PASSWORD,s)},resetPassword:async s=>{await n.post(o.RESET_PASSWORD,s)}},x=()=>{const s=U(),r=C(),l=y();if(!l)return{user:null,isAuthenticated:!1,isLoadingUser:!1,login:()=>{},logout:()=>{},changePassword:()=>{},resetPassword:()=>{},isLoggingIn:!1,isLoggingOut:!1,isChangingPassword:!1,isResettingPassword:!1};const{setUser:A,setTokens:L,logout:w,user:_,isAuthenticated:m}=l,P=u({mutationFn:a.login,onSuccess:e=>{A(e.user),L(e.tokens.access,e.tokens.refresh),r.setQueryData(g.auth.user(),e.user),i.success("Login successful"),s(c.DASHBOARD)},onError:e=>{const E=I(e)||"Invalid email or password";i.error(E,{duration:5e3})}}),h=u({mutationFn:a.logout,onSuccess:()=>{w(),r.clear(),i.success("Logged out successfully"),s(c.LOGIN)},onError:()=>{w(),r.clear(),s(c.LOGIN)}}),p=u({mutationFn:a.changePassword,onSuccess:()=>{i.success("Password changed successfully")}}),f=u({mutationFn:a.resetPassword,onSuccess:()=>{i.success("Password reset email sent")}}),{data:O,isLoading:q}=S({queryKey:g.auth.user(),queryFn:a.getCurrentUser,enabled:m,staleTime:1/0});return{user:O||_,isAuthenticated:m,isLoadingUser:q,login:e=>P.mutate(e),logout:()=>h.mutate(),changePassword:e=>p.mutate(e),resetPassword:e=>f.mutate(e),isLoggingIn:P.isPending,isLoggingOut:h.isPending,isChangingPassword:p.isPending,isResettingPassword:f.isPending}},D=()=>{const{isAuthenticated:s}=y();return S({queryKey:g.auth.user(),queryFn:a.getCurrentUser,enabled:s})},F=d({identifier:t().min(1,"Email or username is required"),password:t().min(1,"Password is required")}),T=d({old_password:t().min(1,"Current password is required"),new_password:t().min(8,"Password must be at least 8 characters").regex(/[A-Z]/,"Password must contain at least one uppercase letter").regex(/[a-z]/,"Password must contain at least one lowercase letter").regex(/[0-9]/,"Password must contain at least one number").regex(/[^A-Za-z0-9]/,"Password must contain at least one special character"),new_password_confirm:t().min(1,"Please confirm your new password")}).refine(s=>s.new_password===s.new_password_confirm,{message:"Passwords do not match",path:["new_password_confirm"]}),b=d({email:t().email("Please enter a valid email address")});export{D as a,T as c,F as l,b as r,x as u};
