import {
  formatLocalMatchDateTime,
  isAfterLocalTodayMatchWindow,
  isInLocalTodayMatchWindow,
  isoToPlatformPickerDateTime,
  platformPickerDateTimeToIso,
} from '@thebet365/shared';

describe('match time helpers', () => {
  it('converts Malaysia picker time to UTC ISO and back', () => {
    const iso = platformPickerDateTimeToIso('2026-06-11T19:00:00');

    expect(iso).toBe('2026-06-11T11:00:00.000Z');
    expect(isoToPlatformPickerDateTime(iso)).toBe('2026-06-11T19:00:00');
  });

  it('formats the same kickoff in different local time zones with GMT offsets', () => {
    const malaysia = formatLocalMatchDateTime('2026-06-11T11:00:00.000Z', 'en-US', {
      variant: 'full',
      timeZone: 'Asia/Kuala_Lumpur',
    });

    const newYork = formatLocalMatchDateTime('2026-06-11T11:00:00.000Z', 'en-US', {
      variant: 'full',
      timeZone: 'America/New_York',
    });

    expect(malaysia).toContain('07:00');
    expect(malaysia).toContain('GMT+8');
    expect(newYork).toContain('07:00');
    expect(newYork).toContain('GMT-4');
    expect(malaysia).not.toBe(newYork);
  });

  it('keeps early next-day matches in the player today bucket until local noon', () => {
    const now = new Date('2026-06-11T15:00:00-04:00');

    expect(isInLocalTodayMatchWindow('2026-06-12T02:00:00.000Z', now, 'America/New_York')).toBe(
      true,
    );
    expect(isInLocalTodayMatchWindow('2026-06-12T15:59:59.000Z', now, 'America/New_York')).toBe(
      true,
    );
    expect(isAfterLocalTodayMatchWindow('2026-06-12T16:00:00.000Z', now, 'America/New_York')).toBe(
      true,
    );
  });
});
