import { localeTag, formatNumber, formatRelativeTime, formatClock } from './number';

describe('localeTag', () => {
  it('maps fa to fa-IR and anything else to en-US', () => {
    expect(localeTag('fa')).toBe('fa-IR');
    expect(localeTag('en')).toBe('en-US');
  });
});

describe('formatNumber', () => {
  it('renders Persian digits for fa', () => {
    expect(formatNumber(1234, 'fa')).toBe('۱٬۲۳۴');
  });

  it('renders Latin digits for en', () => {
    expect(formatNumber(1234, 'en')).toBe('1,234');
  });
});

describe('formatRelativeTime', () => {
  const absolute = () => 'ABSOLUTE_DATE';

  it('renders a minute-grain relative phrase for a recent timestamp', () => {
    const iso = new Date(Date.now() - 5 * 60 * 1000).toISOString();
    const result = formatRelativeTime(iso, 'en', absolute);
    expect(result).toMatch(/minute/);
  });

  it('decays to the absolute formatter past 7 days', () => {
    const iso = new Date(Date.now() - 10 * 24 * 60 * 60 * 1000).toISOString();
    expect(formatRelativeTime(iso, 'en', absolute)).toBe('ABSOLUTE_DATE');
  });

  it('returns an empty string for an invalid date', () => {
    expect(formatRelativeTime('not-a-date', 'en', absolute)).toBe('');
  });
});

describe('formatClock', () => {
  it('formats mm:ss under an hour', () => {
    expect(formatClock(125, 'en')).toBe('02:05');
  });

  it('formats hh:mm:ss past an hour', () => {
    expect(formatClock(3661, 'en')).toBe('01:01:01');
  });

  it('clamps negative durations to zero', () => {
    expect(formatClock(-5, 'en')).toBe('00:00');
  });
});
