import{n as e}from"./BNTlsKDJ.js";import{X as t,bt as n,vt as r}from"./BT3KAag_.js";import{t as i}from"./9bCTHkeS.js";function a(){return i(`/api/auth/status`)}function o(){return i(`/api/auth/me`)}function s(e,t){return i(`/api/auth/login`,{method:`POST`,body:JSON.stringify({email:e,password:t})})}function c(){return i(`/api/auth/logout`,{method:`POST`})}function l(e,t,n){return i(`/api/auth/setup`,{method:`POST`,body:JSON.stringify({email:e,password:t,displayName:n})})}function u(){return i(`/api/auth/users`)}function d(e,t,n,r){return i(`/api/auth/users`,{method:`POST`,body:JSON.stringify({email:e,password:t,displayName:n,role:r})})}function f(e){return i(`/api/auth/users/${e}/deletion-preview`)}function p(e){return i(`/api/auth/users/${e}`,{method:`DELETE`})}function m(e){return i(`/api/auth/me`,{method:`PATCH`,body:JSON.stringify(e)})}function h(e,t){return i(`/api/auth/users/${e}/password`,{method:`PATCH`,body:JSON.stringify({password:t})})}function g(e,t){return i(`/api/auth/users/${e}`,{method:`PATCH`,body:JSON.stringify(t)})}function _(){return i(`/api/auth/tokens`)}function v(e){return i(`/api/auth/tokens`,{method:`POST`,body:JSON.stringify({name:e})})}function y(e){return i(`/api/auth/tokens/${e}`,{method:`DELETE`})}var b=e({auth:()=>D}),x=n(null),S=n(null),C=n(!1),w=n(!1),T=n(!0),E=n(``),D={get user(){return t(x)},get personRef(){return t(S)},get authEnabled(){return t(C)},get needsSetup(){return t(w)},get loading(){return t(T)},get workspaceName(){return t(E)},async checkAuth(){r(T,!0);try{let e=await a();if(r(C,e.authEnabled,!0),r(w,e.userCount===0),e.workspaceName&&r(E,e.workspaceName,!0),t(w))return r(T,!1),{authenticated:!1,authEnabled:!1,needsSetup:!0};if(!e.authEnabled)return r(T,!1),{authenticated:!0,authEnabled:!1,needsSetup:!1};try{let{user:e,personRef:t}=await o();return r(x,e,!0),r(S,t,!0),r(T,!1),{authenticated:!0,authEnabled:!0,needsSetup:!1}}catch{return r(x,null),r(S,null),r(T,!1),{authenticated:!1,authEnabled:!0,needsSetup:!1}}}catch{return r(T,!1),{authenticated:!0,authEnabled:!1,needsSetup:!1}}},async login(e,t){let{user:n}=await s(e,t);return r(x,n,!0),r(C,!0),n},async setup(e,t,n){let{user:i}=await l(e,t,n);return r(x,i,!0),r(C,!0),r(w,!1),i},async logout(){await c(),r(x,null),r(S,null)}};export{p as a,f as c,g as d,m as f,d as i,h as l,b as n,_ as o,v as r,u as s,D as t,y as u};