declare global { interface Window { __APP_CONFIG__?: { apiBase?: string; }; } } function normalizeBase(base: string): string { return base.replace(/\/+$/, ''); } export function getApiBase(): string { if (typeof window !== 'undefined' && window.__APP_CONFIG__?.apiBase) { return normalizeBase(window.__APP_CONFIG__.apiBase); } if (typeof process !== 'undefined' && process.env?.API_BASE_URL) { return normalizeBase(process.env.API_BASE_URL); } return '/api'; } export function getSupabaseApiUrl(): string { const base = getApiBase(); if (base.startsWith('http://') || base.startsWith('https://')) { return base; } if (typeof window !== 'undefined') { return `${window.location.origin}${base}`; } return base; } export function buildApiUrl(path: string): string { const base = getApiBase(); const suffix = path.startsWith('/') ? path : `/${path}`; if (base.startsWith('http://') || base.startsWith('https://')) { return `${base}${suffix}`; } return `${base}${suffix}`; }