import { getNextReminderSchedule } from './journalReminder';

function toLocalDateString(date) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}

describe('journalReminder', () => {
  it('calculates Easter-relative reminders correctly', () => {
    const entry = {
      pickupDate: '2025-04-20',
      reminder: {
        enabled: true,
        interval: 'yearly',
        beforeUnit: 'weeks',
        beforeValue: 6,
        reference: {
          mode: 'event',
          eventKey: 'easter_sunday',
          occurrenceOffsetUnit: 'weeks',
          occurrenceOffsetValue: 2
        }
      }
    };

    const schedule = getNextReminderSchedule(entry, new Date('2026-01-10T00:00:00'));

    expect(schedule).not.toBeNull();
    expect(toLocalDateString(schedule.occurrence)).toBe('2026-04-19');
    expect(toLocalDateString(schedule.reminderDate)).toBe('2026-03-08');
  });

  it('keeps fixed pickup-date reminders working', () => {
    const entry = {
      pickupDate: '2024-12-24',
      reminder: {
        enabled: true,
        interval: 'yearly',
        beforeUnit: 'weeks',
        beforeValue: 2
      }
    };

    const schedule = getNextReminderSchedule(entry, new Date('2026-01-10T00:00:00'));

    expect(schedule).not.toBeNull();
    expect(toLocalDateString(schedule.occurrence)).toBe('2026-12-24');
    expect(toLocalDateString(schedule.reminderDate)).toBe('2026-12-10');
  });
});
