export type AuthRuntimeConfig = {
  authApiOrigin?: string;
  authBasePath?: string;
};

export function getAuthApiOrigin(config?: AuthRuntimeConfig): string {
  const direct = (config?.authApiOrigin ?? process.env.NEXT_PUBLIC_AUTH_BASE_URL)?.trim();
  if (direct) return direct.replace(/\/$/, "");
  if (typeof window !== "undefined") return window.location.origin;
  return "http://localhost:3001";
}

export function getAuthBasePath(config?: AuthRuntimeConfig): string {
  const configured = (config?.authBasePath ?? process.env.NEXT_PUBLIC_AUTH_BASE_PATH)?.trim();
  if (!configured || configured === "/") return "/api/auth";
  return configured.startsWith("/") ? configured : `/${configured}`;
}
