import { describe, expect, it } from 'vitest';
import { formatShowTime, lobbyStartText } from './format';

// 2026-10-30 21:00 in New York (EDT, UTC-4) = 2026-10-31T01:00Z.
const NINE_PM_NY = Date.UTC(2026, 9, 31, 1, 0);
const MIN = 60_000;
const TZ = 'America/New_York';

describe('lobbyStartText', () => {
  it('shows the clock time only when the show is due within the hour', () => {
    expect(lobbyStartText(NINE_PM_NY, NINE_PM_NY - 45 * MIN, TZ)).toMatch(/^Starts at 9:00\sPM$/u);
    expect(lobbyStartText(NINE_PM_NY, NINE_PM_NY - 60 * MIN, TZ)).toMatch(/^Starts at 9:00\sPM$/u);
  });

  it('leaves it to the host for a lobby opened early, a show already due, or no schedule', () => {
    expect(lobbyStartText(NINE_PM_NY, NINE_PM_NY - 61 * MIN, TZ)).toBe('Starts when the host is ready');
    expect(lobbyStartText(NINE_PM_NY, NINE_PM_NY - 24 * 60 * MIN, TZ)).toBe('Starts when the host is ready');
    expect(lobbyStartText(NINE_PM_NY, NINE_PM_NY + MIN, TZ)).toBe('Starts when the host is ready');
    expect(lobbyStartText(null, NINE_PM_NY, TZ)).toBe('Starts when the host is ready');
  });
});

describe('formatShowTime', () => {
  it('names the day relative to now', () => {
    expect(formatShowTime(NINE_PM_NY, NINE_PM_NY - 2 * 60 * MIN, TZ)).toMatch(/^Today 9:00\sPM$/u);
    expect(formatShowTime(NINE_PM_NY, NINE_PM_NY - 24 * 60 * MIN, TZ)).toMatch(/^Tomorrow 9:00\sPM$/u);
    expect(formatShowTime(NINE_PM_NY, NINE_PM_NY - 3 * 24 * 60 * MIN, TZ)).toMatch(/^Fri 9:00\sPM$/u);
  });
});
