"use strict";const i="gamifiera-uid";window.addEventListener("DOMContentLoaded",()=>{const t="gamifiera-event";let a=e=>{let r=new URLSearchParams(window.location.search);r.get(i)?n(r.get(i),e):e()},n=(e,r)=>{if(localStorage.getItem(i)===e){r();return}fetch(`${window.gamifieraConfig.apiUrl}/api/userDetails?uid=${e}`).then(o=>o.json()).then(o=>{let{avatarUrl:l,name:s}=o;localStorage.setItem(i,JSON.stringify({uid:e,avatarUrl:l,name:s})),r()})};a(()=>{let e=localStorage.getItem(i);e?e=JSON.parse(e):e=null;let r=new CustomEvent("gamifieraInit",{detail:{user:e}});window.document.dispatchEvent(r)}),window.document.querySelectorAll(`.${t}`).forEach(e=>e.addEventListener("click",r=>{window.Gamifiera.postEvent(r.currentTarget.dataset.gamifieraEventId)},!1))});window.Gamifiera={postEvent:t=>{if(!t)return;let a=localStorage.getItem(i);a&&(a=JSON.parse(a),fetch(`${window.gamifieraConfig.apiUrl}/api/event?userId=${a.uid}`,{method:"POST",body:t}))},get:()=>{let t=localStorage.getItem(i);return t?JSON.parse(t):null},getCustomerToken:t=>{let a=window.Gamifiera.get();a&&fetch(`${window.gamifieraConfig.apiUrl}/api/auth/customer-token/${a.uid}`).then(n=>n.json()).then(n=>{let{token:e}=n;t(e)})}}; //# sourceMappingURL=bundle.cjs.map