/**
 * API utilities for session management and authentication
 */

let sessionExpiredHandled = false;

/**
 * Handle session expiration by redirecting to login
 */
export function handleSessionExpired(): void {
  if (sessionExpiredHandled) return;
  sessionExpiredHandled = true;

  // If we're in the browser, redirect to login
  if (typeof window !== "undefined") {
    window.location.href = "/login?expired=true";
  }
}

/**
 * Check if a session expiration is already being handled
 * (prevents multiple simultaneous redirects)
 */
export function isSessionExpiring(): boolean {
  return sessionExpiredHandled;
}

/**
 * Reset the session expiration flag (for testing)
 */
export function resetSessionExpirationFlag(): void {
  sessionExpiredHandled = false;
}
