import { describe, expect, it } from 'vitest'
import type { DocumentCaptureKind, DocumentExhibit, SourceFileType } from './types'
import { defaultConnectionLabel, documentCapture, documentCaptureRegistry, documentWidget, documentWidgetRegistry, exhibitWidget, exhibitWidgetRegistry, mugshotIdentification } from './exhibitRegistry'

describe('frontend exhibit registry', () => {
  it('registers every normalized exhibit type', () => {
    const types = ['folder', 'document', 'note', 'event', 'party', 'claim'] as const
    expect(Object.keys(exhibitWidgetRegistry).sort()).toEqual([...types].sort())
    expect(exhibitWidget('event').heading({} as never, { exhibits: [], relations: [], dispatch: () => {} })).toContain('THIS HAPPENED')
  })

  it('registers every normalized document type with an explicit renderer', () => {
    const types: SourceFileType[] = ['image', 'pdf', 'web_capture', 'email', 'article', 'filing', 'price_list', 'text', 'file']
    expect(Object.keys(documentWidgetRegistry).sort()).toEqual(types.sort())
    for (const type of types) {
      expect(documentWidget(type).label).toBeTruthy()
      expect(documentWidget(type).Preview).toBeTypeOf('function')
      expect(documentWidget(type).Asset).toBeTypeOf('function')
    }
  })

  it('registers every capture kind with a physical board size', () => {
    const kinds:DocumentCaptureKind[]=['unclassified','photo','scene','clipping','full_page']
    expect(Object.keys(documentCaptureRegistry).sort()).toEqual(kinds.sort())
    for (const kind of kinds) expect(documentCapture(kind).defaultSize).toMatchObject({ width:expect.any(Number),height:expect.any(Number) })
    expect(['full_page','scene','photo','clipping'].map(kind => documentCapture(kind as DocumentCaptureKind).label)).toEqual(['Document','Image','Mugshot','Clip'])
  })

  it('uses structural and image-aware starter copy instead of calling a Party proof', () => {
    const placed={ x:0,y:0,width:100,height:100,rotation:0,zIndex:1,hidden:false }
    const party={ id:'party',type:'party' as const,title:'Nils',content:'',partyKind:'person' as const,aliases:[],...placed }
    const claim={ id:'claim',type:'claim' as const,title:'Inventor',statement:'Nils was an inventor.',...placed }
    const photo:DocumentExhibit={ id:'photo',type:'document',title:'Portrait',body:[],regions:[],fileType:'image',captureKind:'photo',metadata:{},...placed }
    expect(defaultConnectionLabel(party,claim)).toBe('Subject of claim')
    expect(defaultConnectionLabel(photo,party)).toBe('Identified as…')
    expect(defaultConnectionLabel(photo,claim)).toBe('Proof that…')
    const connection={ id:'identity',fromExhibitId:party.id,toExhibitId:photo.id,label:'Identified as…',tightness:65,tagStyle:'luggage' as const,tagPosition:50,tagOffset:0 }
    expect(mugshotIdentification(photo,[party,claim,photo],[connection])).toEqual({ party,connection })
    expect(mugshotIdentification({ ...photo,captureKind:'scene' },[party,photo],[connection])).toBeNull()
  })
})
