// Client-side API key management
// In production, this would use secure cookies or a proper auth system

const STORAGE_KEY = "stemedb-api-key";

export function getApiKey(): string | null {
  if (typeof window === "undefined") {
    return process.env.STEMEDB_API_KEY || null;
  }
  return localStorage.getItem(STORAGE_KEY);
}

export function setApiKey(key: string): void {
  if (typeof window === "undefined") return;
  localStorage.setItem(STORAGE_KEY, key);
}

export function clearApiKey(): void {
  if (typeof window === "undefined") return;
  localStorage.removeItem(STORAGE_KEY);
}

export function hasApiKey(): boolean {
  return getApiKey() !== null;
}
