import{F as e}from"./p-3478f368.js";import{L as t}from"./p-8d78b631.js";class r{_endpoint;_levelupAuthorizePath=`/api/levelup/level-up-authorize`;_levelupTokenGrantPath=`/api/levelup/level-up-token-grant`;levelupLocalStorageKey="levelup";fetchHelper=new e("PnLevelUpService");_storage=new t;constructor(e){this._endpoint=this.formatEndpoint(e)}newLevelupUser(){let e=18e4;this._storage.set(this.levelupLocalStorageKey,{expire:Date.now()+e})}async levelupAuthorize(e,t){if(!e){return t}let r={system:e};const s=this._endpoint+this._levelupAuthorizePath;const n=await this.fetchHelper.fetchJson(s,this.getRequestInit(r),false);return this.handleResponse(n,t)}async levelupTokenGrant(e,t,r){if(!e){return r}let s={id:e,loopSeconds:t};const n=this._endpoint+this._levelupTokenGrantPath;const i=await this.fetchHelper.fetchJson(n,this.getRequestInit(s),false);return this.handleResponse(i,r)}formatEndpoint(e){return e.lastIndexOf("/")===e.length-1?e.substring(0,e.length-1):e}handleResponse(e,t,r=false){if(!e){return t}let s=JSON.parse(e);if(!s||r&&!Array.isArray(s)){return t}return s}getRequestInit(e,t="POST",r="cors",s="application/json"){return{mode:r,method:t,headers:{"Content-Type":s,CustomValidateAntiForgeryToken:"0111000001101110011000110110000101110100"},body:JSON.stringify(e)}}}export{r as P};
//# sourceMappingURL=p-cf8a1fb9.js.map