(()=>{imt.const={cookie_name:"imt",messages_re:/^imt-([\w_-]+)(\((.*?)\))?$/,messages:{lsget:"lsget",lsset:"lsset",enableDebug:"enableDebug",clearCache:"clearCache",saveSessionsToCache:"saveSessionsToCache"},get_method:"GET",post_method:"POST",lambda_delay:2e3};let o={DEBUG:"debug",INFO:"info",ERROR:"error"},e;var i={};function r(e,t,s){if(l()&&"debug"===localStorage.getItem("debug-mode"))switch(e){case o.INFO:console.info(t,s);break;case o.ERROR:console.error(t,s);break;case o.DEBUG:console.debug(t,s)}}function t(e){var t=e.origin.match(/:\/\/(.*?)(:|$)/)[1];if((e=>{if(0<=(e=e.toLowerCase()).indexOf(":")&&(e=e.substr(0,e.indexOf(":"))),"auto"===imt.settings.cookie_domain&&(e===window.location.hostname.toLowerCase()||e.endsWith("."+window.location.hostname.toLowerCase())))return 1;if(Array.isArray(imt.settings.linked_domains))for(var t=0;t{try{return window!==window.top}catch(e){return 1}})())try{void 0!==window.parent.postMessage&&window.parent.postMessage(e,"*")}catch(e){}}function n(e,t){let s="imt-"+e;e=t||null;a(s=e?s+"("+JSON.stringify(e)+")":s)}function l(){try{if(localStorage.setItem("ls_test","1"),"1"===localStorage.getItem("ls_test"))return localStorage.removeItem("ls_test"),1}catch(e){}}function c(){return imt.settings.lambda_url}async function m(e){if(!c())return null;let t="";imt.settings.lambda_url.endsWith("/")||(t=imt.settings.lambda_url+"/");var s=await new Promise(t=>{import("https://openfpcdn.io/fingerprintjs/v3").then(e=>e.load()).then(e=>e.get()).then(e=>{r(o.INFO,"Current Visitor Id "+e.visitorId),t(e.visitorId)}).catch(e=>{t(null),r(o.INFO,"Finger Print Error",e)})});return s?t+=s+(e?"-"+e:"")+(imt.settings.token?"-"+imt.settings.token:""):null}async function u(e,t){e=await m(e);e&&fetch(e,{method:imt.const.post_method,headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(()=>r(o.INFO,"Data successfully saved to Lambda",t)).catch(e=>r(o.ERROR,"Lambda storage error",e))}i[imt.const.messages.lsget]=function(t){c()?(e&&(clearTimeout(e),e=0),e=setTimeout(()=>{(async e=>{if(e=await m(e))try{var t=await(await fetch(e,{method:imt.const.get_method,headers:{"Content-Type":"application/json"}})).json();return r(o.INFO,"Data is successfully retrieved from Lambda",t),t}catch(e){return r(o.ERROR,"Lambda storage error",e),{}}})(t).then(e=>{n("lsget-result",{key:t,value:e.value||null})})},imt.const.lambda_delay)):n("lsget-result",{key:t,value:(e=>{if(l())try{return JSON.parse(localStorage.getItem(e)||"null")}catch(e){}return null})(t)})},i[imt.const.messages.lsset]=function(e){"key"in e&&"value"in e&&(s(e.key,e.value),c()?u(e.key,e.value).then(e=>{n("lsset-result")}):n("lsset-result"))},i[imt.const.messages.saveSessionsToCache]=function(t){"key"in t&&"value"in t&&(s(t.key,t.value),c())&&u(t.key,t.value).then(e=>{r(o.INFO,"Lambda Saved Data when user left the page",t.value)})},i[imt.const.messages.enableDebug]=function(){var e;l()&&localStorage.setItem("debug-mode","debug"),l()&&(e=imt.settings.debug?"debug":"silent",e=localStorage.getItem("debug-mode")||e,localStorage.setItem("debug-mode",e))},i[imt.const.messages.clearCache]=function(){l()&&localStorage.removeItem(imt.const.cookie_name),u(imt.const.cookie_name,{})},void 0!==window.addEventListener?window.addEventListener("message",t,!1):window.attachEvent("onmessage",t)})();