/**
 * Centralized API configuration for Classroom Copilot.
 *
 * Resolves the API base URL from environment variables with proper fallbacks.
 * - In dev: VITE_API_BASE should always be set (e.g., http://192.168.0.64:18000)
 * - In production: VITE_API_BASE should be set to the production API URL
 * - Fallback: "/api" (relative path, works when API is served from same origin)
 *
 * IMPORTANT: Never hardcode localhost or 127.0.0.1 as fallbacks - they break
 * remote dev access and do not work in containerized environments.
 */

/**
 * Primary API base URL. Use this for all API calls.
 * Resolved from VITE_API_BASE (preferred) or VITE_API_URL (legacy alias).
 */
export const API_BASE: string =
  import.meta.env.VITE_API_BASE ||
  import.meta.env.VITE_API_URL ||
  "/api";

/**
 * TLSync worker URL for tldraw multiplayer.
 * Resolved from VITE_TLSYNC_URL (preferred) or derived from VITE_FRONTEND_SITE_URL.
 */
export const TLSYNC_URL: string =
  import.meta.env.VITE_TLSYNC_URL ||
  (import.meta.env.VITE_FRONTEND_SITE_URL?.startsWith("http")
    ? `${import.meta.env.VITE_FRONTEND_SITE_URL}/tldraw`
    : `https://${import.meta.env.VITE_FRONTEND_SITE_URL}/tldraw`);

/**
 * WhisperLive WebSocket URL for live transcription.
 * Resolved from VITE_WHISPERLIVE_URL. Must be set in env.
 */
export const WHISPERLIVE_URL: string | undefined =
  import.meta.env.VITE_WHISPERLIVE_URL;

/**
 * Search proxy URL (searxng).
 * Resolved from VITE_SEARCH_URL.
 */
export const SEARCH_URL: string =
  import.meta.env.VITE_SEARCH_URL || "/searxng-api/";
