var _wpdef_idle_params;"undefined"==typeof wpdef_idle_params&&console.warn("wpdef_idle_params is undefined. Ensure it is properly set for idle detection.");var idleTimer,idleThreshold="undefined"!=typeof wpdef_idle_params&&wpdef_idle_params.timeout?1e3*Math.min(Number((null===(_wpdef_idle_params=wpdef_idle_params)||void 0===_wpdef_idle_params?void 0:_wpdef_idle_params.timeout)||60),2147483):6e4,tabId=Math.random().toString(36).substring(2,11),currentState="active",supportsBroadcastChannel="undefined"!=typeof BroadcastChannel,bc=supportsBroadcastChannel?new BroadcastChannel("idle-detection-channel"):null;function broadcastState(e){supportsBroadcastChannel&&bc&&bc.postMessage({state:e,timestamp:Date.now(),tabId:tabId})}function logoutUser(){"undefined"==typeof wpdef_idle_params||wpdef_idle_params.stop||fetch(wpdef_idle_params.ajax_url+"?action=wpdef_logout",{method:"POST",credentials:"same-origin"}).then(function(){handleLogin(),wpdef_idle_params.stop=!0}).catch(function(){handleLogin(),wpdef_idle_params.stop=!0})}function handleLogin(){var e=window.location.href,t=wpdef_idle_params.login_url+"?redirect_to="+encodeURIComponent(e);window.location.href=t}function setActive(){"idle"!==currentState||arguments.length>0&&void 0!==arguments[0]&&arguments[0]||(currentState="active",broadcastState("active"))}function setIdle(){"idle"!==currentState&&(currentState="idle",broadcastState("idle"),logoutUser())}function resetIdleTimer(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(idleTimer),e||setActive(),idleTimer=setTimeout(setIdle,idleThreshold)}var lastEventTime=0;function throttledResetIdleTimer(){var e=Date.now();e-lastEventTime<200||(lastEventTime=e,resetIdleTimer())}document.addEventListener("mousemove",throttledResetIdleTimer,{passive:!0}),document.addEventListener("wheel",throttledResetIdleTimer,{passive:!0}),document.addEventListener("scroll",throttledResetIdleTimer,{passive:!0}),document.addEventListener("keydown",resetIdleTimer),document.addEventListener("mousedown",resetIdleTimer),document.addEventListener("touchstart",resetIdleTimer),document.addEventListener("visibilitychange",function(){"visible"===document.visibilityState&&resetIdleTimer()}),resetIdleTimer(),supportsBroadcastChannel&&bc?(bc.onmessage=function(e){var t=e.data,d=t.state;t.tabId!==tabId&&"active"===d&&resetIdleTimer(!0)},window.addEventListener("pagehide",function(){bc.close()})):console.warn("BroadcastChannel API is not supported in this browser. Multi-tab idle detection will not work.");
