declare global {
  interface Window {
    Clerk?: {
      session?: {
        getToken: (options?: Record<string, unknown>) => Promise<string>;
      };
    };
  }
}

/**
 * Get a Clerk session JWT without React hooks (works from non-React modules).
 * Returns null if Clerk isn't initialized or user isn't signed in.
 */
export async function getClerkSessionToken(): Promise<string | null> {
  try {
    const clerk = typeof window === "undefined" ? undefined : window.Clerk;
    if (!clerk?.session?.getToken) return null;
    const token = await clerk.session.getToken();
    return token || null;
  } catch {
    return null;
  }
}


