import { generateAuthUrl } from "#/utils/generate-auth-url";
import { GetConfigResponse } from "#/api/option-service/option.types";

interface UseAuthUrlConfig {
  appMode: GetConfigResponse["APP_MODE"] | null;
  identityProvider: string;
  authUrl?: GetConfigResponse["AUTH_URL"];
}

export const useAuthUrl = (config: UseAuthUrlConfig) => {
  if (config.appMode === "saas") {
    return generateAuthUrl(
      config.identityProvider,
      new URL(window.location.href),
      config.authUrl,
    );
  }

  return null;
};
