import { describe, expect, test } from 'vitest'
import { formatEventDate } from './formatEventDate'

// Fri 24.07.2026 18:00 Berlin time
const start = new Date('2026-07-24T18:00:00+02:00')
const endSameDay = new Date('2026-07-24T20:00:00+02:00')
const endNextDay = new Date('2026-07-25T01:00:00+02:00')
const endSunday = new Date('2026-07-26T14:00:00+02:00')

describe('format "long"', () => {
  test('start only', () => {
    expect(formatEventDate(start)).toBe(`Freitag 24.07.26, 18:00 Uhr`)
  })

  test('same-day end renders as time range', () => {
    expect(formatEventDate(start, endSameDay)).toBe(`Freitag 24.07.26, 18:00 - 20:00 Uhr`)
  })

  test('multi-day end renders both dates', () => {
    expect(formatEventDate(start, endSunday)).toBe(
      `Fr. 24.07. 18:00 Uhr - So. 26.07. 14:00 Uhr`,
    )
  })

  test('end after midnight counts as multi-day', () => {
    expect(formatEventDate(start, endNextDay)).toBe(
      `Fr. 24.07. 18:00 Uhr - Sa. 25.07. 01:00 Uhr`,
    )
  })
})

describe('format "short"', () => {
  test('start only', () => {
    expect(formatEventDate(start, undefined, 'short')).toBe(`Freitag, 18:00 Uhr`)
  })

  test('same-day end renders as time range without date', () => {
    expect(formatEventDate(start, endSameDay, 'short')).toBe(`Freitag, 18:00 - 20:00 Uhr`)
  })

  test('multi-day end renders compact weekday range', () => {
    expect(formatEventDate(start, endSunday, 'short')).toBe(`Fr 18:00 - So 14:00 Uhr`)
  })
})

describe('timezone handling', () => {
  test('calendar day is compared in Europe/Berlin, not UTC', () => {
    const lateStart = new Date('2026-07-24T22:30:00Z')
    const earlyEnd = new Date('2026-07-25T01:00:00Z')
    expect(formatEventDate(lateStart, earlyEnd)).toBe(`Samstag 25.07.26, 00:30 - 03:00 Uhr`)
  })
})
