import{isEmpty}from"../../base/helpers.mjs";import{Controller}from"../base.mjs";import{TweaksFormView}from"../../forms/enfugue/tweaks.mjs";class TweaksController extends Controller{getState(e=!0){return{tweaks:this.tweaksForm.values}}setState(e){isEmpty(e.tweaks)||this.tweaksForm.setValues(e.tweaks).then((()=>this.tweaksForm.submit()))}getDefaultState(){return{tweaks:{guidanceScale:this.config.model.invocation.guidanceScale,inferenceSteps:this.config.model.invocation.inferenceSteps,scheduler:null,clipSkip:0,enableFreeU:!1,freeUBackbone1:1.2,freeUBackbone2:1.4,freeUSkip1:.9,freeUSkip2:.2,noiseOffset:0,noiseMethod:"simplex",noiseBlendMethod:"inject"}}}async initialize(){this.tweaksForm=new TweaksFormView(this.config),this.tweaksForm.onSubmit((async e=>{this.engine.guidanceScale=e.guidanceScale,this.engine.inferenceSteps=e.inferenceSteps,this.engine.scheduler=e.scheduler,this.engine.clipSkip=e.clipSkip,this.engine.noiseOffset=e.noiseOffset,this.engine.noiseMethod=e.noiseMethod,this.engine.noiseBlendMethod=e.noiseBlendMethod,e.enableFreeU?this.engine.freeUFactors=[e.freeUBackbone1,e.freeUBackbone2,e.freeUSkip1,e.freeUSkip2]:this.engine.freeUFactors=null})),this.subscribe("modelPickerChange",(e=>{if(!isEmpty(e)){let s=e.defaultConfiguration,i={};isEmpty(s.guidance_scale)||(i.guidanceScale=s.guidance_scale),isEmpty(s.inference_steps)||(i.inferenceSteps=s.inference_steps),isEmpty(s.clip_skip)||(i.clipSkip=s.clip_skip),isEmpty(s.noise_offset)||(i.noiseOffset=s.noise_offset),isEmpty(s.noise_method)||(i.noiseMethod=s.noise_method),isEmpty(s.noise_blend_method)||(i.noiseBlendMethod=s.noise_blend_method),isEmpty(s.freeu_factors)||(i.enableFreeU=!0,i.freeUBackbone1=s.freeu_factors[0],i.freeUBackbone2=s.freeu_factors[1],i.freeUSkip1=s.freeu_factors[2],i.freeUSkip2=s.freeu_factors[3]),isEmpty(e.scheduler)||(i.scheduler=e.scheduler[0].name),isEmpty(i)||this.tweaksForm.setValues(i)}})),this.application.sidebar.addChild(this.tweaksForm)}}export{TweaksController as SidebarController};
