function ViewClip(){throw{msg:"Don't NEW a singleton."}}EventListener.apply(ViewClip),function(){var e,t,i,o,n,h,s,r,a,l,p,g,d,f,u=!0,w=!1,c=!1,C=null,m={height:1440,width:2560},v={height:360,width:640},V={height:360,width:640},E={height:0,width:0},S={top:0,left:0},b={height:0,width:0};this.currentChannel=function(){return ViewManager.getViewObject(0)?ViewManager.getViewObject(0).getChannelId():0},this.setSchedule=function(e){w=e},this.initUI=function(){e=$("#toggle-clip-status"),t=$("#clip-view-frame"),i=$("#clip-target-view"),o=i.find(".left-top-spot"),n=i.find(".right-top-spot"),h=i.find(".left-bottom-spot"),s=i.find(".right-bottom-spot"),e.on("click",(function(){ViewClip.toggleStatus()})),v.width=t.innerWidth(),r=m.width/t.innerWidth(),t.css({height:m.height/r}),this.onAutoUpdatePos();var f=function(){g.left<0?g.left=0:g.left+i.width()>t.innerWidth()&&(g.left=t.innerWidth()-i.width()),g.top<0?g.top=0:g.top+i.height()>t.innerHeight()&&(g.top=t.innerHeight()-i.height())},w=function(e){if(e.stopPropagation(),e.preventDefault(),a){if(l===p){var i=ViewClip.currentChannel();2==PCE.getFeatureVersion("videoClip",i)&&(c?(t.off("mousemove",P).off("mouseup",w).off("mouseleave",w),c=!1):t.off("mousemove",S).off("mouseup",w).off("mouseleave",w)),o=l,ViewClip.setNewPos(g,(function(){l===o&&ViewClip.switchAutoUpdate(!0)}))}a=!1}var o},V=function(e){var o;e.stopPropagation(),e.preventDefault();var n=ViewClip.currentChannel();o=ControllerMain.isNvr?PCE.isWritable("videoClip",n):PCE.isWritable("videoClip"),ViewClip.isEnabledClip()&&o&&(a=!0,p=l=String.random(16),ViewClip.switchAutoUpdate(!1),d={top:e.clientY-t.offset().top,left:e.clientX-t.offset().left},g={left:i.offset().left-t.offset().left,top:i.offset().top-t.offset().top},$(e.target).hasClass("drag-spot")?(c=!0,C=$(e.target),t.on("mousemove",P).on("mouseup",w).on("mouseleave",w)):t.on("mousemove",S).on("mouseup",w).on("mouseleave",w))},S=function(e){e.stopPropagation(),e.preventDefault(),a&&!c&&(g.left+=e.clientX-t.offset().left-d.left,g.top+=e.clientY-t.offset().top-d.top,d={left:e.clientX-t.offset().left,top:e.clientY-t.offset().top},f(),ViewClip.setBoxPos(g))},P=function(e){if(e.stopPropagation(),e.preventDefault(),a){var o=ViewClip.currentChannel();if(2==PCE.getFeatureVersion("videoClip",o)&&c){var n,h,s=C,r=E.width/E.height;s.hasClass("left-top-spot")?(((h=(n=g.top+E.height-(e.clientY-t.offset().top))*(m.width/m.height))m.width||s+n>m.height)return void this.onAutoUpdatePos();var a={channel:i,topLeftX:o,topLeftY:n,cropWidth:h,cropHeight:s,mainWidth:m.width,mainHeight:m.height,screenWidth:m.width,screenHeight:m.height}}else a={channel:i,topLeftX:o,topLeftY:n,screenWidth:m.width,screenHeight:m.height};CGI.sendCommand("SetCrop",{Crop:a},(function(e){window.localStorage.setItem("/player/preview/clip",1),t&&t(!0)}),(function(e,i,o){t&&t(!1),ControllerRemoteConfig.defaultErrorHandle(e,i,o)}))},this.firstRefreshBgImg=!0,this.lastTagId="",this.refreshBgImg=function(e,t=!1){if(this.currentChannel()!==e)return;if(!(t||u&&0!=w&&ViewManager.getMode()==EnumCurState.PREVIEW&&PlayerPreview.allRightSections[5].isShow))return setTimeout((function(){ViewClip.refreshBgImg(e)}),500);var i=document.createElement("img"),o=String.random(16),n=ChannelManager.get(ViewManager.getSelectedView().getChannelId());const h=n?n.getStream():EnumStreamType.FLUENT;var s=["cmd=Snap","channel="+e,"width=320","height=180","rs="+String.random(16)];switch(h){case EnumStreamType.TRACK_FLUENT:s.push("iLogicChannel=1","snapType=sub");break;case EnumStreamType.TRACK_CLEAR:s.push("iLogicChannel=1","snapType=main");break;case EnumStreamType.BALANCED:s.push("snapType=ext");break;case EnumStreamType.CLEAR:s.push("snapType=main");break;case EnumStreamType.FLUENT:default:s.push("snapType=sub")}var r=ControllerLogin.getQueryDataByCount(s,"Snap"),a="";-1!==r&&(a=r.query,r.count.free=!1),i.src="cgi-bin/api.cgi?&token="+infoHandler.recover2Str(ControllerLogin.token)+"&"+a,i.id="clip-bg-ldr-"+o,$(i).css({width:"100%",height:"100%",position:"absolute"});var l=function(t){-1!==r&&(r.count.free=!0),setTimeout((function(){ViewClip.refreshBgImg(e)}),1e4),t?(ViewClip.firstRefreshBgImg?ViewClip.firstRefreshBgImg=!1:$("#clip-bg-ldr-"+ViewClip.lastTagId).remove(),ViewClip.lastTagId=o):$("#clip-bg-ldr-"+o).remove(),i=null,o=null};i.onload=()=>l(!0),i.onerror=i.onabort=()=>l(!1),document.getElementById("clip-view-frame").appendChild(i)},this.setBoxPos=function(e){e.top+E.height>v.height&&(e.top=v.height-E.height),e.left+E.width>v.width&&(e.left=v.width-E.width),i.css(e)},this.setBoxPosSize=function(){i.css({height:V.height,width:V.width})},this.setDrewBoxWidth=function(){i.css({height:E.height,width:E.width})}}.apply(ViewClip);