import"./rolldown-runtime-DIIn1E2Q.js";import{D as e,c as t,kt as n,mt as r}from"./vendor-vue-core-DO0afONr.js";import{r as i}from"./api-Cw7jP9TY.js";var a=t(`user`,()=>{let t=n(null),a=n(null),o=e(()=>t.value&&`users`in t.value),s=e(()=>!a.value&&o.value),c=e(()=>Object.entries(t.value?.users??{}).map(([e,t])=>({userId:e,username:t}))),l=e(()=>c.value.find(e=>e.userId===a.value)??null),u=e(()=>t.value!==null);async function initialize(){t.value=await i.getUserConfig(),a.value=localStorage[`Comfy.userId`]}async function createUser(e){let t=await i.createUser(e),n=await t.json();if(t.status>=300)throw Error(n.error??`Error creating user: `+t.status+` `+t.statusText);return{userId:n,username:e}}async function login({userId:e,username:t}){a.value=e,localStorage[`Comfy.userId`]=e,localStorage[`Comfy.userName`]=t}r(()=>{o.value&&a.value&&(i.user=a.value)});async function logout(){delete localStorage[`Comfy.userId`],delete localStorage[`Comfy.userName`]}return{users:c,currentUser:l,isMultiUserServer:o,needsLogin:s,initialized:u,initialize,createUser,login,logout}});export{a as t};
//# sourceMappingURL=userStore-Czt6jT20.js.map