import{c as t,h as e}from"./p-ee1e0eb4.js";import{r,g as n}from"./p-5d409601.js";import{H as a}from"./p-b06e2bef.js";import{T as o,A as i}from"./p-7dae0f0e.js";import{A as s}from"./p-2f569553.js";const c=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,i,s,c=t[0]||{},l=1,u=t.length,p=!1;for("boolean"==typeof c&&(p=c,c=t[l]||{},l++),"object"!=typeof c&&"function"!=typeof c&&(c={}),l===u&&(c=this,l--);l<u;l++)if(null!==(e=t[l]))for(r in e)n=c[r],o=e[r],c!==o&&(a=Array.isArray(n)?"array":typeof n,p&&o&&((i=Array.isArray(o))||"object"==typeof o)?(i?(i=!1,s=n&&"array"===a?n:[]):s=n&&"object"===a?n:{},c[r]=this.extend(p,s,o)):void 0!==o&&(c[r]=o));return c}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 l(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),e.Sparkle.config;console.error("Sparkle config was already initialized")}async function u(e){await c.loadScriptAsync(t("../assets/lib/sparkle.js")),await l(e)}class p{constructor(){}static getInstance(){return p.instance||(p.instance=new p),p.instance}async authenticate(t){const e={"Content-Type":"application/json"};let r;s.state.loading=!0;try{if(r=await a.http.post("api/Account/Authenticate",t,{headers:e}),r){const t=r.Data,e={Id:t.Id,UserName:t.UserName,Email:t.Email,Roles:t.Roles,IsVerified:t.IsVerified,JWToken:t.JWToken,IssuedOn:t.IssuedOn,ExpiresOn:t.ExpiresOn,RefreshToken:t.RefreshToken,PhotoUrl:"",IsFacilitator:t.Roles.indexOf("Facilitator")>0};return await o.getInstance().saveAuthUser(e),s.state.loading=!1,e}}catch(t){return s.state.loading=!1,t}}async signOut(){await r(i.AUTH_USER_LOCALSTORAGE),await o.getInstance().removeAuthUser(),sessionStorage.clear()}async getLocalAuthUser(){return n(i.AUTH_USER_LOCALSTORAGE)}}const f=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 i=r;return e("stencil-route",Object.assign({},o,{routeRender:t=>s.state.isAuthenticated?n&&!sparkle.auth.isGranted(n)?e("stencil-router-redirect",{url:"/unauthorized"}):i?e(i,Object.assign({},t,t.componentProps)):a(t):e("stencil-router-redirect",{url:"/login"})}))};export{p as A,f as P,u as i,l as s}