import { describe, it, expect } from 'vitest'
import { buildNotePdf } from '../pdf'
import { emptyDocument, type NoteDocument } from '../document'

describe('buildNotePdf', () => {
  it('produces a non-empty A4 PDF blob for a drawn portrait page', async () => {
    const doc: NoteDocument = {
      version: 2,
      orientation: 'portrait',
      background: 'grid',
      gridMm: 5,
      pages: [
        {
          version: 1,
          strokes: [
            { points: [[10, 10, 0.5], [50, 50, 0.6], [90, 10, 0.7]], color: '#037493', size: 6 },
          ],
        },
      ],
    }
    const blob = await buildNotePdf(doc)
    expect(blob.size).toBeGreaterThan(0)
    expect(blob.type).toBe('application/pdf')
  })

  it('renders text labels into the PDF without throwing', async () => {
    const doc: NoteDocument = {
      version: 2,
      orientation: 'portrait',
      background: 'blank',
      gridMm: 5,
      pages: [
        {
          version: 1,
          strokes: [],
          texts: [{ x: 100, y: 200, text: 'Wertstrom Linie 3', color: '#D93025', size: 28 }],
        },
      ],
    }
    const blob = await buildNotePdf(doc)
    expect(blob.size).toBeGreaterThan(0)
    expect(blob.type).toBe('application/pdf')
  })

  it('handles landscape + lines + a blank page without throwing', async () => {
    const doc: NoteDocument = {
      version: 2,
      orientation: 'landscape',
      background: 'lines',
      gridMm: 8,
      pages: [emptyDocument().pages[0], { version: 1, strokes: [] }],
    }
    const blob = await buildNotePdf(doc)
    expect(blob.size).toBeGreaterThan(0)
  })
})
