import{isEmpty,deepClone}from"../../base/helpers.mjs";import{Controller}from"../base.mjs";import{UpscaleStepsFormView}from"../../forms/enfugue/upscale.mjs";class UpscaleController extends Controller{getState(e=!0){return this.upscaleForm.submit(),{upscale:this.upscaleForm.values.steps}}getDefaultState(){return{upscale:[]}}setState(e){let s=deepClone(e.upscale);null===s?s=[]:Array.isArray(s)||(s="object"!=typeof s||isEmpty(s[0])?[s]:Object.getOwnPropertyNames(s).map((e=>s[e]))),this.upscaleForm.setValues({steps:s}).then((()=>{setTimeout((()=>this.upscaleForm.submit()),250)}))}async initialize(){this.upscaleForm=new UpscaleStepsFormView(this.config),this.upscaleForm.onSubmit((async e=>{this.engine.upscaleSteps=e.steps})),this.subscribe("modelPickerChange",(e=>{if(!isEmpty(e)){let s=e.defaultConfiguration,t={};isEmpty(s.upscale_steps)||(t.steps=s.steps),isEmpty(t)||this.upscaleForm.setValues(t)}})),this.subscribe("quickUpscale",(e=>{this.upscaleForm.setValues({steps:[e]})})),this.application.sidebar.addChild(this.upscaleForm)}}export{UpscaleController as SidebarController};
