var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __async=(__this,__arguments,generator)=>new Promise((resolve,reject)=>{var fulfilled=value=>{try{step(generator.next(value))}catch(e){reject(e)}},rejected=value=>{try{step(generator.throw(value))}catch(e){reject(e)}},step=x=>x.done?resolve(x.value):Promise.resolve(x.value).then(fulfilled,rejected);step((generator=generator.apply(__this,__arguments)).next())});import{j as createSpinner,g as api,$ as $el}from"./index-Dj_yIC5Q.js";const _UserSelectionScreen=class _UserSelectionScreen{show(users,user){return __async(this,null,function*(){const userSelection=document.getElementById("comfy-user-selection");return userSelection.style.display="",new Promise(resolve=>{const input=userSelection.getElementsByTagName("input")[0],select=userSelection.getElementsByTagName("select")[0],inputSection=input.closest("section"),selectSection=select.closest("section"),form=userSelection.getElementsByTagName("form")[0],error=userSelection.getElementsByClassName("comfy-user-error")[0],button=userSelection.getElementsByClassName("comfy-user-button-next")[0];let inputActive=null;if(input.addEventListener("focus",()=>{inputSection.classList.add("selected"),selectSection.classList.remove("selected"),inputActive=!0}),select.addEventListener("focus",()=>{inputSection.classList.remove("selected"),selectSection.classList.add("selected"),inputActive=!1,select.style.color=""}),select.addEventListener("blur",()=>{select.value||(select.style.color="var(--descrip-text)")}),form.addEventListener("submit",e=>__async(this,null,function*(){var _a,_b,_c;if(e.preventDefault(),inputActive==null)error.textContent="Please enter a username or select an existing user.";else if(inputActive){const username=input.value.trim();if(!username){error.textContent="Please enter a username.";return}input.disabled=select.disabled=input.readonly=select.readonly=!0;const spinner=createSpinner();button.prepend(spinner);try{const resp=yield api.createUser(username);if(resp.status>=300){let message="Error creating user: "+resp.status+" "+resp.statusText;try{const res=yield resp.json();res.error&&(message=res.error)}catch(error2){}throw new Error(message)}resolve({username,userId:yield resp.json(),created:!0})}catch(err){spinner.remove(),error.textContent=(_c=(_b=(_a=err.message)!=null?_a:err.statusText)!=null?_b:err)!=null?_c:"An unknown error occurred.",input.disabled=select.disabled=input.readonly=select.readonly=!1;return}}else if(select.value)resolve({username:users[select.value],userId:select.value,created:!1});else{error.textContent="Please select an existing user.";return}})),user){const name=localStorage["Comfy.userName"];name&&(input.value=name)}input.value&&input.focus();const userIds=Object.keys(users!=null?users:{});if(userIds.length){for(const u of userIds)$el("option",{textContent:users[u],value:u,parent:select});select.style.color="var(--descrip-text)",select.value&&select.focus()}else userSelection.classList.add("no-users"),input.focus()}).then(r=>(userSelection.remove(),r))})}};__name(_UserSelectionScreen,"UserSelectionScreen");let UserSelectionScreen=_UserSelectionScreen;window.comfyAPI=window.comfyAPI||{};window.comfyAPI.userSelection=window.comfyAPI.userSelection||{};window.comfyAPI.userSelection.UserSelectionScreen=UserSelectionScreen;export{UserSelectionScreen}; //# sourceMappingURL=userSelection-Dh-tiIjz.js.map