import {describe, expect, test} from 'bun:test'

import {reminderOptions} from '@/lib/reminders'

const now = new Date('2026-07-01T12:00:00')

describe('reminderOptions', () => {
  test('offers anchored offsets at 9am for a far-out visit', () => {
    const anchor = new Date('2026-07-20T18:00:00')
    const labels = reminderOptions(anchor, now).map((o) => o.label)
    expect(labels).toEqual([
      'A week before',
      'The day before',
      'That morning',
      'Tomorrow morning',
      'Next week',
    ])
    const [weekBefore] = reminderOptions(anchor, now)
    expect(weekBefore!.remindAt).toEqual(
      new Date('2026-07-13T09:00:00'),
    )
  })

  test('drops offsets that land in the past', () => {
    const anchor = new Date('2026-07-03T18:00:00')
    const labels = reminderOptions(anchor, now).map((o) => o.label)
    expect(labels).not.toContain('A week before')
    expect(labels).toContain('The day before')
  })

  test('dedupes options that resolve to the same moment', () => {
    // visit tomorrow: "that morning" and "tomorrow morning" coincide
    const anchor = new Date('2026-07-02T18:00:00')
    const times = reminderOptions(anchor, now).map((o) =>
      o.remindAt.getTime(),
    )
    expect(new Set(times).size).toBe(times.length)
  })

  test('offers relative options without an anchor', () => {
    expect(reminderOptions(null, now).map((o) => o.label)).toEqual([
      'Tomorrow morning',
      'Next week',
    ])
  })
})
