const AUTH_HINT_KEY = "compton-auth-hint";
const PROTECTED_PATH_PREFIXES = ["/admin", "/profile"] as const;

export function markAuthSessionHint(): void {
  sessionStorage.setItem(AUTH_HINT_KEY, "1");
}

export function clearAuthSessionHint(): void {
  sessionStorage.removeItem(AUTH_HINT_KEY);
}

export function hasAuthSessionHint(): boolean {
  return sessionStorage.getItem(AUTH_HINT_KEY) === "1";
}

export function isProtectedAppPath(pathname: string): boolean {
  return PROTECTED_PATH_PREFIXES.some(
    (prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`)
  );
}

export function shouldAttemptAuthRefresh(pathname = window.location.pathname): boolean {
  return hasAuthSessionHint() || isProtectedAppPath(pathname);
}
