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,chunkingMaskType:this.config.model.invocation.chunkingMaskType}}}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.chunkingMaskType=i.chunkingMaskType):this.engine.chunkingSize=0})),this.application.sidebar.addChild(this.canvasForm),this.subscribe("modelPickerChange",(async i=>{if(!isEmpty(i)){let n=i.defaultConfiguration,s={};isEmpty(n.width)||(s.width=n.width),isEmpty(n.height)||(s.height=n.height),isEmpty(n.chunking_size)||(s.chunkingSize=n.chunking_size,0===s.chunkingSize&&(s.useChunking=!1)),isEmpty(n.chunking_mask_type)||(s.chunkingMaskType=n.chunking_mask_type),isEmpty(s)||(isEmpty(s.useChunking)&&(s.useChunking=!0),await this.canvasForm.setValues(s),await this.canvasForm.submit())}})),this.subscribe("applicationReady",(()=>this.canvasForm.submit()))}}export{CanvasController as SidebarController};
