import { describe, expect, it } from 'vitest';
import {
  getAuthRoleLabel,
  getNextSignupStep,
  getPreviousSignupStep,
  getSignupCampusName,
  validateSignupStepOne,
} from '@/business/auth/selectors';
import type { AuthModalDraft } from '@/business/auth/types';
import { toCampusCatalogViewModels } from '@/business/campuses/mappers';
import { campusCatalogItemSeed } from '@/test-seeds/campuses';

const validDraft: AuthModalDraft = {
  email: 'staff@example.com',
  password: 'secret1',
  confirmPassword: 'secret1',
  fullName: 'Ava Lee',
  role: 'teacher',
  campus: 'tigers',
  showPassword: false,
};

describe('auth selectors', () => {
  const campuses = toCampusCatalogViewModels([campusCatalogItemSeed]);

  it('validates sign-up step one in field order', () => {
    expect(validateSignupStepOne(validDraft)).toBeNull();
    expect(validateSignupStepOne({ ...validDraft, fullName: '  ' })).toBe('Please enter your full name');
    expect(validateSignupStepOne({ ...validDraft, email: 'invalid' })).toBe('Please enter a valid email address');
    expect(validateSignupStepOne({ ...validDraft, password: 'short', confirmPassword: 'short' })).toBe(
      'Password must be at least 6 characters',
    );
    expect(validateSignupStepOne({ ...validDraft, confirmPassword: 'different' })).toBe('Passwords do not match');
  });

  it('keeps signup step navigation inside the supported range', () => {
    expect(getNextSignupStep(1)).toBe(2);
    expect(getNextSignupStep(2)).toBe(3);
    expect(getNextSignupStep(3)).toBe(3);
    expect(getPreviousSignupStep(3)).toBe(2);
    expect(getPreviousSignupStep(2)).toBe(1);
    expect(getPreviousSignupStep(1)).toBe(1);
  });

  it('maps campus and role display labels', () => {
    expect(getSignupCampusName('tigers', campuses)).toBe('Tigers');
    expect(getSignupCampusName('', campuses)).toBeNull();
    expect(getAuthRoleLabel('support_staff')).toBe('Support Staff');
    expect(getAuthRoleLabel('office_manager')).toBe('Office Manager');
  });
});
