import { describe, expect, it } from 'vitest';
import {
  clampNumber,
  formatTimerTime,
  getTimerProgress,
  getTimerUrgencyColor,
  parseBoundedInteger,
} from '@/business/classroom-timer/selectors';
import type { SensoryBackground } from '@/shared/types/classroomTimer';

const background: SensoryBackground = {
  id: 'ocean',
  name: 'Ocean Calm',
  iconId: 'waves',
  image: 'ocean.png',
  overlay: 'from-blue-950/40 via-blue-900/20 to-cyan-950/40',
  textColor: 'text-blue-100',
  accentColor: 'text-blue-300',
  ringColor: 'stroke-blue-400',
  trackColor: 'stroke-blue-900/50',
};

describe('classroom timer selectors', () => {
  it('formats timer seconds as mm:ss', () => {
    expect(formatTimerTime(0)).toBe('00:00');
    expect(formatTimerTime(65)).toBe('01:05');
    expect(formatTimerTime(600)).toBe('10:00');
  });

  it('calculates progress and handles zero totals', () => {
    expect(getTimerProgress(100, 25)).toBe(0.25);
    expect(getTimerProgress(0, 25)).toBe(0);
  });

  it('selects urgency color from finish and progress thresholds', () => {
    expect(getTimerUrgencyColor(true, 0.5, background)).toBe('text-red-400 animate-pulse');
    expect(getTimerUrgencyColor(false, 0.1, background)).toBe('text-red-300');
    expect(getTimerUrgencyColor(false, 0.25, background)).toBe('text-amber-300');
    expect(getTimerUrgencyColor(false, 0.5, background)).toBe('text-blue-100');
  });

  it('clamps and parses bounded integers', () => {
    expect(clampNumber(12, 1, 10)).toBe(10);
    expect(clampNumber(-2, 1, 10)).toBe(1);
    expect(parseBoundedInteger('7', 1, 10)).toBe(7);
    expect(parseBoundedInteger('invalid', 1, 10)).toBe(1);
  });
});
