import{MenuController}from"../menu.mjs";import{isEmpty}from"../../base/helpers.mjs";import{FormView}from"../../view/forms/base.mjs";import{CheckboxInputView,NumberInputView}from"../../view/forms/input.mjs";class SystemSettingsView extends FormView{static fieldSets={Safety:{safe:{label:"Use Safety Checker",class:CheckboxInputView,config:{value:!0,tooltip:"The Safety Checker will evaluate images after they have been diffused to determine if they contain explicit content. If they do, the image will not be saved, and a blank image will be returned."}}},Users:{auth:{label:"Use Authentication",class:CheckboxInputView,config:{value:!1,tooltip:"When checked, you will be required to use a username and password to login to the application before you will be able to use it."}}},Diffusion:{maxQueuedInvocations:{label:"Queue Size",class:NumberInputView,config:{required:!0,value:2,min:0,step:1,tooltip:"The maximum number of invocations to queue. Invocations are queued when a user tries to use the diffusion engine while it is currently in use with another invocation. If there are no queue slots available, the user who attempts to use the engine will receive an error."}}},Downloads:{maxConcurrentDownloads:{label:"Concurrent Downloads",class:NumberInputView,config:{required:!0,value:2,min:1,max:10,step:1,tooltip:"The maximum number of downloads to allow at once."}},maxQueuedDownloads:{label:"Queue Size",class:NumberInputView,config:{required:!0,value:2,min:0,step:1,max:10,tooltip:"The maximum number of downloads to queue."}}}}}class SystemSettingsController extends MenuController{static menuName="Settings";static menuIcon="fa-solid fa-gear";static settingsWindowWidth=600;static settingsWindowHeight=510;getSettings(){return this.model.get("/settings")}updateSettings(e){return this.model.post("/settings",null,null,e)}async getSettingsView(){let e=await this.getSettings(),t={safe:e.safe,auth:e.auth,maxQueuedInvocations:e.max_queued_invocations,maxQueuedDownloads:e.max_queued_downloads,maxConcurrentDownloads:e.max_concurrent_downloads};return isEmpty(this.settingsView)?(this.settingsView=new SystemSettingsView(this.config,t),this.settingsView.onSubmit((async t=>{try{await this.updateSettings({safe:t.safe,auth:t.auth,max_queued_invocations:t.maxQueuedInvocations,max_queued_downloads:t.maxQueuedDownloads,max_concurrent_downloads:t.maxConcurrentDownloads}),t.auth!==e.auth?(this.notify("info","Settings Updated","Successfully updated settings. Reloading page to update authentication data…"),setTimeout((()=>window.location.href="/logout"),2e3)):this.notify("info","Settings Updated","Successfully updated settings.")}catch(e){let t=`${e}`;isEmpty(e.detail)?isEmpty(e.title)||(t=e.title):t=e.detail,this.notify("error","Couldn't Update Settings",t)}this.settingsView.enable()}))):this.settingsView.setValues(t),this.settingsView}async showSettingsManager(){isEmpty(this.settingsManager)?(this.settingsManager=await this.spawnWindow("Settings",await this.getSettingsView(),this.constructor.settingsWindowWidth,this.constructor.settingsWindowHeight),this.settingsManager.onClose((()=>{this.settingsManager=null}))):this.settingsManager.focus()}async onClick(){this.showSettingsManager()}}export{SystemSettingsController as MenuController};
