import{isEmpty}from"../../base/helpers.mjs";import{CanvasFormView}from"../../forms/enfugue/canvas.mjs";import{Controller}from"../base.mjs";class CanvasController extends Controller{getState(i=!0){return{canvas:this.canvasForm.values}}getDefaultState(){return{canvas:{width:this.config.model.invocation.width,height:this.config.model.invocation.height,useChunking:!0,chunkingSize:this.config.model.invocation.chunkingSize,chunkingBlur:this.config.model.invocation.chunkingBlur}}}setState(i){isEmpty(i.canvas)||this.canvasForm.setValues(i.canvas).then((()=>this.canvasForm.submit()))}async initialize(){this.canvasForm=new CanvasFormView(this.config),this.canvasForm.onSubmit((async i=>{this.images.setDimension(i.width,i.height),this.engine.width=i.width,this.engine.height=i.height,i.useChunking?(this.engine.chunkingSize=i.chunkingSize,this.engine.chunkingBlur=i.chunkingBlur):this.engine.chunkingSize=0})),this.application.sidebar.addChild(this.canvasForm),this.subscribe("modelPickerChange",(async i=>{if(!isEmpty(i)){let n=i.defaultConfiguration,t={};isEmpty(n.width)||(t.width=n.width),isEmpty(n.height)||(t.height=n.height),isEmpty(n.chunking_size)||(t.chunkingSize=n.chunking_size,0===t.chunkingSize&&(t.useChunking=!1)),isEmpty(n.chunking_blur)||(t.chunkingBlur=n.chunking_blur),isEmpty(t)||(isEmpty(t.useChunking)&&(t.useChunking=!0),await this.canvasForm.setValues(t),await this.canvasForm.submit())}}))}}export{CanvasController as SidebarController};
