!function(){"use strict";function e(e,t,n,o){return new(n||(n=Promise))((function(i,s){function a(e){try{c(o.next(e))}catch(e){s(e)}}function r(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}c((o=o.apply(e,t||[])).next())}))}(()=>{const t="1a2ef4bc-0d86-4de7-bd0c-c792aafe85bd",n="https://load.nootiz.com",o=`nootiz-${t}`,i="nootiz-login",s="nootiz-login-token",a=window;if(a.Nootiz||(a.Nootiz={}),a.Nootiz.instances||(a.Nootiz.instances=[]),a.Nootiz.instances.includes(t))return;a.Nootiz.instances.push(t);const r=i=>e(void 0,void 0,void 0,(function*(){return new Promise((e=>{const s=()=>{a.removeEventListener("load",s);const r=i=>{if(i.origin!==n)return e();let s=i.data;if(s.apikey!==t)return e();localStorage.setItem(o,JSON.stringify(s)),window.removeEventListener("message",r),e()};window.addEventListener("message",r),a.contentWindow.postMessage({apiKey:t,loginToken:i,send:!0},n)},a=document.createElement("iframe");a.setAttribute("src",`${n}/login`),a.style.setProperty("display","none","important"),a.addEventListener("load",s),document.body.appendChild(a)}))})),c=()=>{const e=()=>{c.removeEventListener("load",e);window.addEventListener("message",(o=>{if(o.origin!==n)return;let s=Object.assign({},o.data);s.apikey===t&&(s.token||(s=Object.assign(Object.assign({},s),i())),s.token&&d(s.language||"en",s.version,s.token,a),c.removeEventListener("load",e))})),c.contentWindow.postMessage(r,n)},i=()=>{const e=localStorage.getItem(o);return e&&JSON.parse(e)||{}},a=()=>{localStorage.removeItem(o),c.contentWindow.postMessage(Object.assign(Object.assign({},r),{logout:!0}),n)},r={apikey:t,token:localStorage.getItem(s)},c=document.createElement("iframe");c.setAttribute("src",`${n}/auth-handler/${t}`),c.style.setProperty("display","none","important"),c.addEventListener("load",e),document.body.appendChild(c)},d=(e,o,i,s)=>{const a=document.body;if(document.getElementById(":nootiz:"))return console.error("you are logged in within multiple nootiz-projects. It is not possible to use more than one nootiz-instance at the same time.");localStorage.setItem("nootiz-api-key",t);const r=document.createElement("script");r.setAttribute("src",`${n}/${e}/${o}/${t}`),r.setAttribute("defer",""),r.addEventListener("load",(()=>{"undefined"!=typeof Nootiz&&Nootiz.init(i,s)})),a.appendChild(r)};e(void 0,void 0,void 0,(function*(){const e=new URLSearchParams(location.search),t=e.get(i);if(t&&localStorage.setItem(s,t),t){yield r(t),e.delete(i);const n=e.toString(),o=location.hash;history.replaceState({},document.title,location.pathname+(n?"?"+n:"")+(o?"#"+o:""))}c()}))})()}();
