import{c as e,i as t,t as n}from"./axios-Ba4xKhTU.js";import{ai as r}from"./endpoints-DlZlVT68.js";var i=class extends Error{};i.prototype.name=`InvalidTokenError`;function a(e){return decodeURIComponent(atob(e).replace(/(.)/g,(e,t)=>{let n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n=`0`+n),`%`+n}))}function o(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`);switch(t.length%4){case 0:break;case 2:t+=`==`;break;case 3:t+=`=`;break;default:throw Error(`base64 string is not of the correct length`)}try{return a(t)}catch{return atob(t)}}function s(e,t){if(typeof e!=`string`)throw new i(`Invalid token specified: must be a string`);t||={};let n=t.header===!0?0:1,r=e.split(`.`)[n];if(typeof r!=`string`)throw new i(`Invalid token specified: missing part #${n+1}`);let a;try{a=o(r)}catch(e){throw new i(`Invalid token specified: invalid base64 for part #${n+1} (${e.message})`)}try{return JSON.parse(a)}catch(e){throw new i(`Invalid token specified: invalid json for part #${n+1} (${e.message})`)}}async function c(e){return await n.post(t+r,e,{headers:{Accept:`application/json`,"Content-Type":`application/json`}})}function l(t){localStorage.setItem(e,t)}function u(){return localStorage.getItem(e)}function d(){return localStorage.removeItem(e)}function f(){let e=u();return!e||p(e)?(d(),null):s(e)}function p(e){if(!e||typeof e!=`string`)return!0;try{let{exp:t}=s(e);return t*1e3-Date.now()<0}catch{return!0}}function m(e){if(!e||typeof e!=`string`)return null;try{let{_:t}=s(e);return t}catch{return null}}export{m as a,d as i,f as n,l as o,c as r,s,u as t};