import { describe, expect, it } from 'vitest';
import { resolveOnboardingRedirect } from './onboardingGuard';
import {
  ADMIN_BILLING_PATH,
} from '../../constants';

describe('resolveOnboardingRedirect', () => {
  it('returns null when events exist', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: true,
      hasActivePackage: false,
      remainingEvents: null,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('returns null for billing paths', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: false,
      remainingEvents: null,
      pathname: ADMIN_BILLING_PATH,
      isBillingPath: true,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('returns null for event creation path', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: true,
      remainingEvents: 1,
      pathname: '/event-admin/mobile/events/new',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('redirects to billing when no active package', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: false,
      remainingEvents: null,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBe(ADMIN_BILLING_PATH);
  });

  it('returns null when no remaining events but an active package exists', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: true,
      remainingEvents: 0,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('returns null when remaining events are available', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: true,
      remainingEvents: 2,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('returns null when remaining events are unlimited', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: true,
      remainingEvents: null,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: false,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('does not redirect when onboarding is dismissed', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: false,
      remainingEvents: null,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingDismissed: true,
      isOnboardingCompleted: false,
    });
    expect(result).toBeNull();
  });

  it('does not redirect when onboarding is completed', () => {
    const result = resolveOnboardingRedirect({
      hasEvents: false,
      hasActivePackage: false,
      remainingEvents: null,
      pathname: '/event-admin/mobile/dashboard',
      isBillingPath: false,
      isOnboardingCompleted: true,
    });
    expect(result).toBeNull();
  });
});
