"use strict";function showLog(){let v=chTabActive?"active":"inactive",u=window.location.pathname,t="-------------------------- > ",n=t+"Path ["+u+"] is "+v.toUpperCase()+"<\/b>",i=chActionTabs.find(n=>n.path===u);i!=undefined&&(n+="
"+t+" Time ACTIVE: "+i.timeActive+"s, INACTIVE: "+i.timeInactive+'s, session expired in '+chCountdown.toHhMmSs()+"<\/span>",n+="
"+t+" Tab ID: "+i.uid,n+="
"+t+" Start active: "+i.startActive,n+="
"+t+" Start inactive: "+i.startInactive,n+="
"+t+" Last active: "+i.lastActive,n+="
"+t+" Last inactive: "+i.lastInactive);let f=getCookie(chKeyClientId),r=getCookie(chKeySessionId);n+=")
"+t+" Client ID: "+f;n+="
"+t+" Session ID: "+(r==null?"EXPIRED":r)+"<\/b>";chClientId==null&&(chClientId=f);chSessionId==null&&(chSessionId=r);(r==null||chCountdown<=0)&&invokeHub("CloseSession");let e=window.screen.height,o=window.screen.width;n+="
"+t+" Screen (h,w) = ("+e+","+o;chScreenSize=[e,o];let s=$(window).height(),h=$(window).width();n+=") | Window (h,w) = ("+s+","+h;let y=[s,h],c=$(document).height(),l=$(document).width();n+=")
"+t+" Document (h,w) = ("+c+","+l;let p=[c,l];n+=") | Mouse (x,y) = ("+chMouseX+","+chMouseY+")";let a=[chMouseX,chMouseY];chMouseInfos.length>0?chMouseInfos[0].mousePosition.push(a):chMouseInfos=[{windowSize:y,documentSize:p,mousePosition:[a]}];$("#zlog").html(n)}function invokeHub(n){if(chSignalR!=null){chZLogUi&&console.log("Calling "+n+"...");let i=getActionTab(),t={clientId:chClientId,sessionId:chSessionId,sessionExpired:n=="CloseSession",sessionClosed:n=="CloseTab",tabs:[i],screenSize:chScreenSize,mouseInfos:chMouseInfos,browser:detectBrowser()};(t.sessionExpired||t.sessionClosed)&&(chSessionId=null,setStorageS(chKeyActionTab,null),clearInterval(chTimer));let r=JSON.stringify(t);chSignalR.invoke(n,r).then(function(){chZLogUi&&console.log("Called "+n+"...")}).catch(function(n){console.log(n.message)})}}function insertLog(n,t=null,i=null){if(chSignalR!=null){isEmpty(i)&&(i=window.location.search);let r=getCookie("TabId");chSignalR.invoke("InsertLog",r,n,t,i).catch(function(n){console.log(n.message)})}}function sendMessage(n,t){chSignalR!=null&&chSignalR.invoke("SendMessage",n,t).catch(function(n){console.log(n.message)})}function invokeMessage(n,t,i){chSignalR!=null&&chSignalR.invoke("InvokeMessage",n,t,i).catch(function(n){console.log(n.message)})}function updateActionTab(n){let t=getActionTab();t==undefined?(t=new ActionTab(window.location.pathname),setCookie("TabId",t.uid),insertLog(t.uid,window.location.pathname),n?calcActive(t):calcInactive(t),chActionTabs.push(t)):n?calcActive(t):calcInactive(t);setStorageS(chKeyActionTab,chActionTabs)}function setActionTab(n){let i=new Date,t=getActionTab();t==undefined?(t=new ActionTab(window.location.pathname),setCookie("TabId",t.uid),insertLog(t.uid,window.location.pathname),n?t.lastActive=i:t.lastInactive=i,chActionTabs.push(t)):n?t.lastActive=i:t.lastInactive=i;setStorageS(chKeyActionTab,chActionTabs)}function getActionTab(){let n=getStorageS(chKeyActionTab);n!=null&&(chActionTabs=n);let t=window.location.pathname;return chActionTabs.find(n=>n.path===t)}function calcActive(n){n.timeActive+=1;n.lastActive=new Date;chCountdown=chSessionCookie*60;let t=getCookie(chKeySessionId);setCookie(chKeySessionId,t,chSessionCookie);t=getCookie(chKeyTabId);setCookie(chKeyTabId,t,chSessionCookie)}function calcInactive(n){n.timeInactive+=1;n.lastInactive=new Date;n.startInactive==null&&(n.startInactive=n.lastInactive)}function handleMouseMove(n){let r,t,i;n=n||window.event;n.pageX==null&&n.clientX!=null&&(r=n.target&&n.target.ownerDocument||document,t=r.documentElement,i=r.body,n.pageX=n.clientX+(t&&t.scrollLeft||i&&i.scrollLeft||0)-(t&&t.clientLeft||i&&i.clientLeft||0),n.pageY=n.clientY+(t&&t.scrollTop||i&&i.scrollTop||0)-(t&&t.clientTop||i&&i.clientTop||0));chMouseX=n.pageX;chMouseY=n.pageY}var chSignalR=null,chClientId=null,chSessionId=null,chTabActive=!0,chActionTabs=[],chKeyActionTab="ActionTab",chKeyClientId="ClientId",chKeySessionId="SessionId",chKeyTabId="TabId",chSessionCookie=1,chCountdown=chSessionCookie*60,chZLogUi=!1,chTimer,chCounter=0,chMouseX=0,chMouseY=0,chScreenSize=[],chMouseInfos=[];setStorageS(chKeyActionTab,null);$(function(){$.ajax({method:"GET",url:prefixApi.authorize+"GetConfig"}).done(n=>{if(n.success){let t=n.data;setConfig(t);chKeyActionTab=t.keyActionTab;chKeyClientId=t.keyClientId;chKeySessionId=t.keySessionId;chKeyTabId=t.keyTabId;chSessionCookie=t.sessionCookie;chZLogUi=t.zLogUi;chSignalR=(new signalR.HubConnectionBuilder).withUrl(t.basePath+"/CounterHub").build();chSignalR.on("ReceiveMessage",function(n,t){console.log(n+": "+t+"\n")});chSignalR.on("DoItNow",function(n,t,i){console.log(n+": "+t+", data:"+i+"\n");$(n).val(i);t=="click"&&$(n).click();t=="keypress"&&$(n).keypress()});chSignalR.start().then(function(){console.log("Starting counter online...")}).catch(function(n){return console.error(n.toString())});let i=new URL(window.location.href);chZLogUi=i.searchParams.get("zlog")==""||chZLogUi;chZLogUi&&$("#zlog").show();setCookie("TabId",createUid());setTimeout(function(){insertLog(window.location.pathname)},2e3)}else console.log(n.message)});let n=!1,t=null;$("*").bind("mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick",function(){n==!0&&(chTabActive=!0);n=!1;clearTimeout(t);t=setTimeout(function(){chTabActive=!1;n=!0},2e3)});$("body").trigger("mousemove");document.onmousemove=handleMouseMove;window.onbeforeunload=function(){invokeHub("CloseTab")};window.onfocus=function(){chTabActive=!0;setActionTab(chTabActive)};window.onblur=function(){chTabActive=!1;setActionTab(chTabActive)};clearInterval(chTimer);chTimer=setInterval(function(){updateActionTab(chTabActive);chCounter%10==0&&(chCounter=0,invokeHub("UpdateTab"));chCounter++;chCountdown--;chCountdown<=0&&clearInterval(chTimer);showLog()},1e3);showLog()});class ActionTab{constructor(n){this.path=n;this.uid=createUid();this.timeActive=1;this.timeInactive=0;this.startActive=new Date;this.startInactive=null;this.lastActive=null;this.lastInactive=null}}