import { describe, it, expect } from 'vitest'
import { mergeTimelineItems } from '@/components/ideas/idea-timeline'

describe('mergeTimelineItems', () => {
  it('sorteert reverse-chronologisch: nieuwste entry staat eerst', () => {
    const logs = [
      { id: 'l1', type: 'NOTE', content: 'oud', metadata: null, created_at: '2024-01-01T10:00:00.000Z' },
    ]
    const questions = [
      {
        id: 'q1',
        question: 'Vraag?',
        options: null,
        status: 'open' as const,
        answer: null,
        created_at: '2024-01-03T12:00:00.000Z',
        expires_at: '2024-01-10T12:00:00.000Z',
      },
    ]
    const userQuestions = [
      {
        id: 'uq1',
        question: 'Mijn vraag',
        answer: null,
        status: 'pending' as const,
        created_at: '2024-01-02T08:00:00.000Z',
      },
    ]

    const result = mergeTimelineItems(logs, questions, userQuestions)

    expect(result).toHaveLength(3)
    expect(result[0].created_at).toBe('2024-01-03T12:00:00.000Z')
    expect(result[0].kind).toBe('question')
    expect(result[1].created_at).toBe('2024-01-02T08:00:00.000Z')
    expect(result[1].kind).toBe('user_question')
    expect(result[2].created_at).toBe('2024-01-01T10:00:00.000Z')
    expect(result[2].kind).toBe('log')
  })

  it('geeft lege lijst terug bij geen input', () => {
    expect(mergeTimelineItems([], [], [])).toEqual([])
  })
})
