class a extends Error {
}
a.prototype.name = "InvalidTokenError";
function c(r) {
  return decodeURIComponent(atob(r).replace(/(.)/g, (e, t) => {
    let n = t.charCodeAt(0).toString(16).toUpperCase();
    return n.length < 2 && (n = "0" + n), "%" + n;
  }));
}
function l(r) {
  let e = r.replace(/-/g, "+").replace(/_/g, "/");
  switch (e.length % 4) {
    case 0:
      break;
    case 2:
      e += "==";
      break;
    case 3:
      e += "=";
      break;
    default:
      throw new Error("base64 string is not of the correct length");
  }
  try {
    return c(e);
  } catch {
    return atob(e);
  }
}
function s(r, e) {
  if (typeof r != "string")
    throw new a("Invalid token specified: must be a string");
  e || (e = {});
  const t = e.header === !0 ? 0 : 1, n = r.split(".")[t];
  if (typeof n != "string")
    throw new a(`Invalid token specified: missing part #${t + 1}`);
  let o;
  try {
    o = l(n);
  } catch (i) {
    throw new a(`Invalid token specified: invalid base64 for part #${t + 1} (${i.message})`);
  }
  try {
    return JSON.parse(o);
  } catch (i) {
    throw new a(`Invalid token specified: invalid json for part #${t + 1} (${i.message})`);
  }
}
const u = (r) => {
  if (!r)
    return !1;
  let e = s(r), t = /* @__PURE__ */ new Date();
  return !(!e || ((e == null ? void 0 : e.exp) ?? 0) * 1e3 < t.getTime());
}, f = (r) => {
  if (!r)
    return "";
  let e = s(r);
  return (e == null ? void 0 : e.runner) ?? "";
};
export {
  f as getVirtualRunnerUrl,
  u as validateJwt
};
