import{a as t,h as e}from"./p-3d23a42a.js";import{c as r,H as n}from"./p-68c1261b.js";const a=new class{constructor(){this.sample=t=>t[Math.floor(Math.random()*t.length)],this.keyBy=(t,e,r)=>t.reduce(((t,n)=>(t[e(n)]=r?r(n):n,t)),{}),this.debounce=(t,e)=>{let r=null;return(...n)=>{clearTimeout(r),r=setTimeout(t,e,...n)}}}loadScript(t){var e=document.createElement("script");e.type="text/javascript",e.src=t,document.body.appendChild(e)}loadScriptAsync(t){return new Promise((function(e,r){const n=document.createElement("script");let a=!1;n.type="text/javascript",n.src=t,n.async=!0,n.onerror=function(t){r(t)},n.onload=n.onreadystatechange=function(){a||this.readyState&&"complete"!=this.readyState||(a=!0,e(!0))};const o=document.getElementsByTagName("script")[0];o.parentElement.insertBefore(n,o)}))}extend(...t){let e,r,n,a,o,s,c,i=t[0]||{},u=1,l=t.length,p=!1;for("boolean"==typeof i&&(p=i,i=t[u]||{},u++),"object"!=typeof i&&"function"!=typeof i&&(i={}),u===l&&(i=this,u--);u<l;u++)if(null!==(e=t[u]))for(r in e)n=i[r],o=e[r],i!==o&&(a=Array.isArray(n)?"array":typeof n,p&&o&&((s=Array.isArray(o))||"object"==typeof o)?(s?(s=!1,c=n&&"array"===a?n:[]):c=n&&"object"===a?n:{},i[r]=this.extend(p,c,o)):void 0!==o&&(i[r]=o));return i}setLocalization(){if(!sparkle.utils.getCookieValue("Sparkle.Localization.CultureName")){let t=navigator.language;sparkle.utils.setCookieValue("Sparkle.Localization.CultureName",t,new Date((new Date).getTime()+15768e7),sparkle.appPath)}}};async function o(t){if(!window)return;const e=window,r=e.Sparkle;if(!r||!r.config||"Object"===r.config.constructor.name)return e.Sparkle=e.Sparkle||{},e.Sparkle.config=Object.assign(Object.assign({},e.Sparkle.config),t),sparkle.config=Object.assign({},t.sparkle),e.Sparkle.config;console.error("Sparkle config was already initialized")}async function s(e){await a.loadScriptAsync(t("../assets/lib/sparkle.js")),await o(e)}const c=window.localStorage,i="enc_auth_token",{state:u,onChange:l,reset:p}=r({authUser:null,bearer:"Bearer ",isAuthenticated:!1});l("authUser",(t=>{u.bearer="Bearer "+(t?t.JWToken:""),u.isAuthenticated=t&&!!t.Id}));const f={state:u,onChange:l,reset:p};class d{constructor(){}static getInstance(){return d.instance||(d.instance=new d),d.instance}async authenticate(t){let e=await n.http.post("api/Account/Authenticate",t,{headers:{"Content-Type":"application/json"}});if(e){const n=e.Data,a={Id:n.Id,UserName:n.UserName,Email:n.Email,Roles:n.Roles,IsVerified:n.IsVerified,JWToken:n.JWToken,IssuedOn:n.IssuedOn,ExpiresOn:n.ExpiresOn,RefreshToken:n.RefreshToken,PhotoUrl:"",IsFacilitator:n.Roles.indexOf("Facilitator")>0},o=t.RememberClient?new Date(a.ExpiresOn):void 0;return sparkle.auth.setToken(a.JWToken,o),sparkle.utils.setCookieValue(i,a.JWToken,o,sparkle.appPath),await("CurrentUser",r=a,new Promise(((t,e)=>{try{c&&c.setItem("CurrentUser",JSON.stringify(r)),t()}catch(t){e("Couldnt store object "+t)}}))),f.state.authUser=Object.assign({},a),a}var r}async signOut(){await("CurrentUser",new Promise(((t,e)=>{try{c&&c.removeItem("CurrentUser"),t()}catch(t){e("Couldnt remove object "+t)}}))),sessionStorage.clear(),sparkle.auth.clearToken(),f.state.authUser=null,f.state.isAuthenticated=!1}async getLocalAuthUser(){return function(){try{if(c){const t=c.getItem("CurrentUser");return JSON.parse(t)}}catch(t){return null}}()}}const h=t=>{var{component:r,permission:n,render:a}=t,o=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(r[n[a]]=t[n[a]])}return r}(t,["component","permission","render"]);const s=r;return e("stencil-route",Object.assign({},o,{routeRender:t=>f.state.isAuthenticated?n&&!sparkle.auth.isGranted(n)?e("stencil-router-redirect",{url:"/unauthorized"}):s?e(s,Object.assign({},t,t.componentProps)):a(t):e("stencil-router-redirect",{url:"/login"})}))};export{d as A,h as P,f as a,s as i,o as s}