export function shouldUseSSO() {
  const appEnv = import.meta.env.VITE_APP_ENVIRONMENT || "local";
  return appEnv.startsWith("prod") || appEnv.startsWith("stage");
}

function constructURL(basePath: string, params = {}) {
  const queryParams = new URLSearchParams(params);
  return `${basePath}${queryParams.toString() ? `?${queryParams}` : ""}`;
}

export function getLoginURL(params = {}) {
  const basePath = shouldUseSSO() ? "/sso/login" : "/login-local";
  return constructURL(basePath, params);
}

export function getSignUpURL(params = {}) {
  return constructURL("/sso/signup", params);
}

export function getLoginURLNext() {
  return getLoginURL({ next: window.location.pathname });
}
