import o from "jwt-decode";
import { debugTmp as r } from "../../utils.js";
class f {
  constructor(e) {
    this.storageKey = e;
  }
  setToken(e) {
    if (!(typeof window > "u" || typeof window.localStorage > "u"))
      return localStorage.setItem(this.storageKey, e);
  }
  getToken() {
    if (typeof window > "u" || typeof window.localStorage > "u")
      return;
    const e = localStorage.getItem(this.storageKey);
    let t, n;
    try {
      if ({ value: t, exp: n } = JSON.parse(e), n === void 0 || t === void 0)
        return e;
    } catch {
      t = e;
    }
    try {
      n = o(t).exp;
    } catch {
      return;
    }
    if (!((/* @__PURE__ */ new Date()).getTime() > n * 1e3))
      return t;
  }
  removeToken() {
    if (r("[LocalStorageEngine] removeToken"), !(typeof window > "u" || typeof window.localStorage > "u"))
      return localStorage.removeItem(this.storageKey);
  }
}
export {
  f as default
};
