import {
  ADMIN_EVENT_CREATE_PATH,
  ADMIN_BILLING_PATH,
} from '../../constants';

type OnboardingRedirectInput = {
  hasEvents: boolean;
  hasActivePackage: boolean;
  remainingEvents?: number | null;
  pathname: string;
  isBillingPath: boolean;
  isOnboardingDismissed?: boolean;
  isOnboardingCompleted?: boolean;
};

export function resolveOnboardingRedirect({
  hasEvents,
  hasActivePackage,
  remainingEvents,
  pathname,
  isBillingPath,
  isOnboardingDismissed,
  isOnboardingCompleted,
}: OnboardingRedirectInput): string | null {
  if (isOnboardingDismissed || isOnboardingCompleted) {
    return null;
  }

  if (isBillingPath) {
    return null;
  }

  if (pathname.startsWith(ADMIN_EVENT_CREATE_PATH)) {
    return null;
  }

  if (!hasEvents && !hasActivePackage) {
    return ADMIN_BILLING_PATH;
  }

  return null;
}
