import { describe, it, expect } from 'vitest'
import { buildAgendaPdf } from '../export-pdf'
import { buildExportModel } from '../export-model'
import { fixtureAgenda, fixtureCtx, ONE_PX_PNG } from './fixtures'

describe('buildAgendaPdf', () => {
  it('produces a non-empty pdf blob without logos', async () => {
    const model = buildExportModel(fixtureAgenda(), fixtureCtx())
    const blob = await buildAgendaPdf(model)
    expect(blob.size).toBeGreaterThan(0)
    expect(blob.type).toBe('application/pdf')
  })

  it('embeds host + up to two supplier logos without throwing', async () => {
    const model = buildExportModel(fixtureAgenda(), fixtureCtx())
    const blob = await buildAgendaPdf(model, {
      hostLogoPng: ONE_PX_PNG,
      supplierLogoPngs: [ONE_PX_PNG, ONE_PX_PNG, ONE_PX_PNG],
    })
    expect(blob.size).toBeGreaterThan(0)
  })

  it('paginates a large multi-day agenda without throwing', async () => {
    const big = fixtureAgenda()
    big.days[0].items = Array.from({ length: 40 }, (_, i) => ({
      ...big.days[0].items[0],
      id: `x${i}`,
      sort_order: i,
      title: `Agenda item number ${i} with a fairly long subject to force wrapping`,
    }))
    const model = buildExportModel(big, fixtureCtx())
    const blob = await buildAgendaPdf(model)
    expect(blob.size).toBeGreaterThan(0)
  })

  it('handles empty days and no participants', async () => {
    const model = buildExportModel(fixtureAgenda({ participants: [], days: [] }), fixtureCtx())
    const blob = await buildAgendaPdf(model)
    expect(blob.size).toBeGreaterThan(0)
  })
})
