const DEFAULT_API_BASE_URL = "/api/v1";

function normalizeBaseUrl(value: string): string {
  const trimmed = value.trim();
  if (!trimmed) return DEFAULT_API_BASE_URL;
  return trimmed.length > 1 ? trimmed.replace(/\/+$/, "") : trimmed;
}

export const API_BASE_URL = normalizeBaseUrl(
  import.meta.env.VITE_API_BASE_URL ?? DEFAULT_API_BASE_URL,
);

export { DEFAULT_API_BASE_URL, normalizeBaseUrl };
