import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{D as t,Dt as n,c as r,mt as i}from"./vendor-vue-core-X6q-rGJs.js";import{r as a}from"./api-DQLKc1Xa.js";const o=r(`user`,()=>{let e=n(null),r=n(null),o=t(()=>e.value&&`users`in e.value),s=t(()=>!r.value&&o.value),c=t(()=>Object.entries(e.value?.users??{}).map(([e,t])=>({userId:e,username:t}))),l=t(()=>c.value.find(e=>e.userId===r.value)??null),u=t(()=>e.value!==null);async function initialize(){e.value=await a.getUserConfig(),r.value=localStorage[`Comfy.userId`]}async function createUser(e){let t=await a.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}){r.value=e,localStorage[`Comfy.userId`]=e,localStorage[`Comfy.userName`]=t}i(()=>{o.value&&r.value&&(a.user=r.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{o as t};
//# sourceMappingURL=userStore-CGYKho9e.js.map