import{isEmpty,isEquivalent}from"../../base/helpers.mjs";import{ElementBuilder}from"../../base/builder.mjs";import{SimpleNotification}from"../../common/notify.mjs";import{View}from"../../view/base.mjs";import{ImageView}from"../../view/image.mjs";import{AnimationView}from"../../view/animation.mjs";import{ToolbarView}from"../../view/menu.mjs";import{UpscaleFormView,DownscaleFormView}from"../../forms/enfugue/upscale.mjs";import{ImageAdjustmentView,ImageFilterView}from"./filter.mjs";const E=new ElementBuilder;class SampleView extends View{constructor(i){super(i),this.animationViews=new Array(9).fill(null).map((()=>new AnimationView(this.config))),this.imageViews=new Array(9).fill(null).map(((i,e)=>new ImageView(this.config,null,4===e))),this.image=null,this.tileHorizontal=!1,this.tileVertical=!1}static tagName="enfugue-sample";get width(){return isEmpty(this.image)?null:Array.isArray(this.image)?this.animationViews[4].width:this.imageViews[4].width}get height(){return isEmpty(this.image)?null:Array.isArray(this.image)?this.animationViews[4].height:this.imageViews[4].height}checkVisibility(){for(let i=0;i<9;i++){let e=this.imageViews[i],t=this.animationViews[i],s=!0;switch(i){case 0:case 2:case 6:case 8:s=this.tileHorizontal&&this.tileVertical;break;case 1:case 7:s=this.tileVertical;break;case 3:case 5:s=this.tileHorizontal}s?Array.isArray(this.image)?(e.hide(),t.show()):(e.show(),t.hide()):(e.hide(),t.hide())}}async getBlob(){return await this.imageViews[4].getBlob()}getDataURL(){return this.imageViews[4].getDataURL()}setImage(i){if(!isEquivalent(this.image,i))if(this.image=i,Array.isArray(i)){for(let e of this.animationViews)e.setImages(i);window.requestAnimationFrame((()=>{this.checkVisibility(),window.requestAnimationFrame((()=>{this.show()}))}))}else if(isEmpty(this.image)){this.hide();for(let i of this.animationViews)i.clearCanvas()}else{for(let e of this.imageViews)e.setImage(i);Promise.all(this.imageViews.map((i=>i.waitForLoad()))).then((()=>{this.checkVisibility(),window.requestAnimationFrame((()=>{this.show()}))}))}}setFrame(i){this.show();for(let e of this.animationViews)e.setFrame(i)}async build(){let i=await super.build(),e=E.div().class("images-container"),t=E.div().class("animation-container");for(let i of this.imageViews)i.hide(),e.append(await i.getNode());for(let i of this.animationViews)i.hide(),t.append(await i.getNode());return i.content(e,t),i}}export{SampleView};
