import{isEmpty,promptFiles}from"../../base/helpers.mjs";import{View}from"../../view/base.mjs";import{VideoView}from"../../view/video.mjs";import{ImageEditorNodeView}from"./base.mjs";import{NoVideoView}from"./common.mjs";class ImageEditorVideoNodeView extends ImageEditorNodeView{static hideHeader=!0;static nodeTypeName="Video";static className="image-editor-video-node-view";static nodeButtons={...ImageEditorNodeView.nodeButtons,"replace-video":{icon:"fa-solid fa-upload",tooltip:"Replace Video",shortcut:"c",callback:function(){this.replaceVideo()}}};async updateOptions(t){this.updateFit(t.fit),this.updateAnchor(t.anchor,t.offsetX,t.offsetY),this.updateOpacity(t.opacity)}async updateFit(t){this.fit=t,this.content.setFit(t)}async updateAnchor(t,e,i){this.anchor=t,this.offsetX=e||0,this.offsetY=i||0,this.content.setAnchor(this.anchor,this.offsetX,this.offsetY)}async updateOpacity(t){this.opacity=t,(await this.content.getNode()).css("opacity",t)}async replaceVideo(){let t;try{t=await promptFiles("video/*")}catch(t){}if(!isEmpty(t)){let e=new FileReader;e.addEventListener("load",(async()=>{let t=new VideoView(this.config,e.result);await this.setContent(t),this.updateFit(this.fit),this.updateAnchor(this.anchor),this.updateOpacity(this.opacity)})),e.readAsDataURL(t)}}getState(t=!0){let e=super.getState(t);return e.src=t?this.content.src:null,e.anchor=this.anchor||null,e.fit=this.fit||null,e.offsetX=this.offsetX||null,e.offsetY=this.offsetY||null,e.opacity=this.opacity||1,e}async setState(t){await super.setState(t),isEmpty(t.src)?await this.setContent(new NoVideoView(this.config)):await this.setContent(new VideoView(this.config,t.src)),await this.updateFit(t.fit),await this.updateOpacity(t.opacity),await this.updateAnchor(t.anchor,t.offsetX,t.offsetY)}async getCanvasScaleSize(){return isEmpty(this.content.src)?await super.getCanvasScaleSize():(await this.content.waitForLoad(),[8*Math.floor(this.content.width/8),8*Math.floor(this.content.height/8)])}static getDefaultState(){return{classname:this.name}}}export{ImageEditorVideoNodeView};
