import{isEmpty}from"../../base/helpers.mjs";import{MenuController}from"../menu.mjs";import{SystemSettingsFormView}from"../../forms/enfugue/settings.mjs";class SystemSettingsController extends MenuController{static menuName="Settings";static menuIcon="fa-solid fa-gear";static menuShortcut="t";static settingsWindowWidth=460;static settingsWindowHeight=600;getSettings(){return this.model.get("/settings")}updateSettings(t){return this.model.post("/settings",null,null,t)}async getSettingsView(){let t=await this.getSettings();return isEmpty(this.settingsView)?(this.settingsView=new SystemSettingsFormView(this.config,t),this.settingsView.onSubmit((async i=>{if(!this.showWarning||await this.confirm("Changing settings will terminate any active invocation. Continue?")){try{await this.updateSettings(i),i.auth!==t.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(t){let i=`${t}`;isEmpty(t.detail)?isEmpty(t.title)||(i=t.title):i=t.detail,this.notify("error","Couldn't Update Settings",i)}this.settingsView.enable()}else 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()}async initialize(){this.subscribe("invocationBegin",(()=>{this.showWarning=!0})),this.subscribe("invocationComplete",(()=>{this.showWarning=!1})),this.subscribe("invocationError",(()=>{this.showWarning=!1}))}}export{SystemSettingsController as MenuController};
