"use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.syncPollingSwitchConfig=exports.resetBasicPollingState=exports.markNeedMenusRefresh=exports.markNeedKickoutRefresh=exports.computeNeedMenusParam=exports.computeNeedKickoutParam=void 0;var menuPollingBaseTs=0,kickoutPollingBaseTs=0,menuPollingTTL=Number.NaN,kickoutPollingTTL=Number.NaN,needMenusRefreshOnce=!1,needKickoutRefreshOnce=!1,lastKickoutUserId="",isConfiguredTtl=function(e){return Number.isFinite(e)},normalizeTtl=function(e){var o=Number(e);return Number.isFinite(o)?o:Number.NaN},resetBasicPollingState=function(){menuPollingBaseTs=0,kickoutPollingBaseTs=0,menuPollingTTL=Number.NaN,kickoutPollingTTL=Number.NaN,needMenusRefreshOnce=!1,needKickoutRefreshOnce=!1,lastKickoutUserId=""};exports.resetBasicPollingState=resetBasicPollingState;var syncPollingSwitchConfig=function(e){e&&"object"===_typeof(e)&&(void 0!==e.MenuPollingTTL&&null!==e.MenuPollingTTL&&(menuPollingTTL=normalizeTtl(e.MenuPollingTTL)),void 0!==e.KickoutPollingTTL&&null!==e.KickoutPollingTTL&&(kickoutPollingTTL=normalizeTtl(e.KickoutPollingTTL)))};exports.syncPollingSwitchConfig=syncPollingSwitchConfig;var markNeedMenusRefresh=function(){needMenusRefreshOnce=!0};exports.markNeedMenusRefresh=markNeedMenusRefresh;var markNeedKickoutRefresh=function(){needKickoutRefreshOnce=!0,kickoutPollingBaseTs=0};exports.markNeedKickoutRefresh=markNeedKickoutRefresh;var computeNeedMenusParam=function(e){var o=e.now,n=e.hasMenusReady,i=Array.isArray(n)?n.length>0:Boolean(n),t=(o-menuPollingBaseTs)/1e3;return i?needMenusRefreshOnce?(needMenusRefreshOnce=!1,menuPollingBaseTs=o,1):isConfiguredTtl(menuPollingTTL)?menuPollingTTL<=0?1:menuPollingBaseTs?t>=menuPollingTTL?(menuPollingBaseTs=o,1):0:(menuPollingBaseTs=o,1):1:1};exports.computeNeedMenusParam=computeNeedMenusParam;var computeNeedKickoutParam=function(e){var o=e.now,n=e.userId,i=String(n||""),t=(o-kickoutPollingBaseTs)/1e3;return i!==lastKickoutUserId&&(lastKickoutUserId=i,needKickoutRefreshOnce=!0,kickoutPollingBaseTs=0),isConfiguredTtl(kickoutPollingTTL)?kickoutPollingTTL<0?1:needKickoutRefreshOnce?(needKickoutRefreshOnce=!1,kickoutPollingBaseTs=o,1):kickoutPollingBaseTs?kickoutPollingTTL>0&&t>=kickoutPollingTTL?(kickoutPollingBaseTs=o,1):0:(kickoutPollingBaseTs=o,1):needKickoutRefreshOnce?(needKickoutRefreshOnce=!1,kickoutPollingBaseTs=o,1):kickoutPollingBaseTs?0:(kickoutPollingBaseTs=o,1)};exports.computeNeedKickoutParam=computeNeedKickoutParam;