/** @vitest-environment jsdom */
import * as DeckUi from '@overdeck/deck-ui'
import { render } from '@testing-library/react'
import { createElement } from 'react'
import { describe, expect, it } from 'vitest'
import { SIDEBAR_SECTIONS } from '../../lib/sidebar-nav'
import { GALLERY_REGISTRY } from './gallery-registry'

describe('design-system gallery registry', () => {
  it('registers every React component exported by the deck-ui barrel', () => {
    const componentExports = Object.entries(DeckUi)
      .filter(([name, value]) => /^[A-Z]/.test(name) && typeof value === 'function')
      .map(([name]) => name)
      .sort()
    const registered = GALLERY_REGISTRY.map((entry) => entry.name)

    for (const name of componentExports) {
      expect(registered).toContain(name)
    }
  })

  it('renders plans attempt history gallery entries without throwing', () => {
    const names = ['AttemptTimeline', 'AttemptDetailDrawer', 'AutopsyStrip', 'BurnPanel']
    for (const name of names) {
      const entry = GALLERY_REGISTRY.find((candidate) => candidate.name === name)
      expect(entry).toBeDefined()
      const view = render(createElement('div', null, entry!.render()))
      view.unmount()
    }
  })

  it('keeps the gallery discoverable in shell navigation', () => {
    expect(SIDEBAR_SECTIONS.flatMap((section) => section.items)).toContainEqual({
      label: 'Design system',
      href: '/design-system',
    })
  })
})
