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:"perlin",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 i=e.defaultConfiguration,s={};isEmpty(i.guidance_scale)||(s.guidanceScale=i.guidance_scale),isEmpty(i.inference_steps)||(s.inferenceSteps=i.inference_steps),isEmpty(i.clip_skip)||(s.clipSkip=i.clip_skip),isEmpty(i.noise_offset)||(s.noiseOffset=i.noise_offset),isEmpty(i.noise_method)||(s.noiseMethod=i.noise_method),isEmpty(i.noise_blend_method)||(s.noiseBlendMethod=i.noise_blend_method),isEmpty(i.freeu_factors)?s.enableFreeU=!1:(s.enableFreeU=!0,s.freeUBackbone1=i.freeu_factors[0],s.freeUBackbone2=i.freeu_factors[1],s.freeUSkip1=i.freeu_factors[2],s.freeUSkip2=i.freeu_factors[3]),isEmpty(e.scheduler)||(s.scheduler=e.scheduler[0].name),isEmpty(s)||this.tweaksForm.setValues(s)}})),this.application.sidebar.addChild(this.tweaksForm)}}export{TweaksController as SidebarController};
