'use strict';
import { getLoginState } from '../auth/internal-login-states.js';
import { getFormatValue, getDuration, isBefore } from '../dates/date-time.js';
import { isBrowser } from '../lib/environments.js';
import { parseJson } from '../lib/utils.js';
import { isNullOrUndefined } from '../functions/value-checking-functions.js';

var __defProp=Object['defineProperty'],__name=(_0x524e2f,_0x460f71)=>__defProp(_0x524e2f,'name',{'value':_0x460f71,'configurable':!![]});const minutesInHour=-0x13c2+0x2344+-0xf46,cacheDurationSeconds=minutesInHour*minutesInHour,validCacheDateKey='validCacheDate';function setCache(_0x491c14){let _0x266f90={'data':_0x491c14['data'],'cacheDate':getFormatValue(),'absoluteExpirationRelativeToNowSeconds':_0x491c14['absoluteExpirationRelativeToNowSeconds']??cacheDurationSeconds};const _0x158862=buildCacheKey(_0x491c14['key'],_0x491c14['isGlobal']);isBrowser()&&(_0x491c14['useShortTermStorage']?sessionStorage['setItem'](_0x158862,JSON['stringify'](_0x266f90)):localStorage['setItem'](_0x158862,JSON['stringify'](_0x266f90)));}__name(setCache,'setCache');function getCache(_0x1b5c0a){const _0x1d04ba=buildCacheKey(_0x1b5c0a['key'],_0x1b5c0a['isGlobal']);let _0x4af0e8,_0x57be6a;isBrowser()&&(_0x1b5c0a['useShortTermStorage']?_0x57be6a=sessionStorage['getItem'](_0x1d04ba)??void(0x1d69*-0x1+0x13f+0x1c2a):_0x57be6a=localStorage['getItem'](_0x1d04ba)??void(0xc50+0x3b6+-0x24a*0x7));if(!isNullOrUndefined(_0x57be6a)){let _0x374ed0=parseJson(_0x57be6a),_0x501ba7=processStaleCache(_0x374ed0);_0x501ba7?isBrowser()&&localStorage['removeItem'](_0x1b5c0a['key']):_0x4af0e8=_0x374ed0['data'];}return _0x4af0e8;}__name(getCache,'getCache');function setValidCacheDate(_0x4cb4af){isBrowser()&&localStorage['setItem'](validCacheDateKey,_0x4cb4af);}__name(setValidCacheDate,'setValidCacheDate');function processStaleCache(_0x4e38e3){let _0x526c17=_0x4e38e3['absoluteExpirationRelativeToNowSeconds']??cacheDurationSeconds,_0x2ac37e=![];getDuration(_0x4e38e3['cacheDate'])>_0x526c17&&(_0x2ac37e=!![]);if(!_0x2ac37e&&isBrowser()){let _0x3d63cb=localStorage['getItem'](validCacheDateKey);_0x3d63cb&&isBefore(_0x4e38e3['cacheDate'],_0x3d63cb)&&(_0x2ac37e=!![]);}return _0x2ac37e;}__name(processStaleCache,'processStaleCache');function buildCacheKey(_0x48dfc2,_0x4e96b8){if(_0x4e96b8)return _0x48dfc2;return _0x48dfc2+'_'+getLoginState()['userId'];}__name(buildCacheKey,'buildCacheKey');

export { getCache, setCache, setValidCacheDate };
