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:{tileHorizontal:!1,tileVertical:!1,width:this.config.model.invocation.width,height:this.config.model.invocation.height,useTiling:!1,tilingSize:this.config.model.invocation.tilingSize,tilingStride:this.config.model.invocation.tilingStride,tilingMaskType:this.config.model.invocation.tilingMaskType}}}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.hasClass("has-sample")||this.images.setDimension(i.width,i.height),this.engine.width=i.width,this.engine.height=i.height,this.engine.tileHorizontal=i.tileHorizontal,this.engine.tileVertical=i.tileVertical,i.useTiling||i.tileHorizontal||i.tileVertical?(this.engine.tilingSize=i.tilingSize,this.engine.tilingMaskType=i.tilingMaskType,this.engine.tilingStride=isEmpty(i.tilingStride)?64:i.tilingStride):this.engine.tilingStride=0})),this.application.sidebar.addChild(this.canvasForm),this.images.onSetDimension(((i,t)=>{let e=this.canvasForm.values;e.width=i,e.height=t,this.canvasForm.setValues(e).then((()=>this.canvasForm.submit()))})),this.subscribe("applicationReady",(()=>this.canvasForm.submit()))}}export{CanvasController as SidebarController};
