/**
 * Unit tests for BoardBannerCard (U2 — simplified banner).
 *
 * Covers the P1 testing gap flagged by ce-code-review. Verifies:
 * - Renders "私董会 — {topic}" title
 * - Renders "轮次：第 N / M 轮" meta
 * - currentRound defaults to 1 when not provided
 * - Custom currentRound renders correctly
 * - No icons, borders, purple bars, progress bars, or expert chips (U2 simplification)
 *
 * Mount strategy: native Vue createApp + h (no @vue/test-utils dependency),
 * consistent with AssistantText.test.ts / ThinkingBlock.test.ts pattern.
 */

import { afterEach, describe, expect, it } from 'vitest'
import { createApp, h, type App } from 'vue'
import BoardBannerCard from '@/components/chat/messages/BoardBannerCard.vue'

interface Mounted {
  container: HTMLElement
  root: HTMLElement
  app: App
  unmount: () => void
}

function mountBoardBannerCard(props: Record<string, unknown>): Mounted {
  const container = document.createElement('div')
  document.body.appendChild(container)
  const app = createApp({
    render: () => h(BoardBannerCard as never, props as never),
  })
  app.mount(container)
  const root = container.querySelector('.board-banner-card') as HTMLElement
  return { container, root, app, unmount: () => { app.unmount(); container.remove() } }
}

describe('BoardBannerCard — U2 simplified banner', () => {
  let mounted: Mounted | null = null

  afterEach(() => {
    mounted?.unmount()
    mounted = null
  })

  it('renders "私董会 — {topic}" as title', () => {
    mounted = mountBoardBannerCard({ topic: '技术选型讨论', maxRounds: 5 })
    const title = mounted.container.querySelector('.board-banner-card__title') as HTMLElement
    expect(title).toBeTruthy()
    expect(title.textContent).toBe('私董会 — 技术选型讨论')
  })

  it('renders "轮次：第 N / M 轮" as meta', () => {
    mounted = mountBoardBannerCard({ topic: '架构评审', maxRounds: 3, currentRound: 2 })
    const meta = mounted.container.querySelector('.board-banner-card__meta') as HTMLElement
    expect(meta).toBeTruthy()
    expect(meta.textContent).toBe('轮次：第 2 / 3 轮')
  })

  it('defaults currentRound to 1 when not provided', () => {
    mounted = mountBoardBannerCard({ topic: '新产品方向', maxRounds: 5 })
    const meta = mounted.container.querySelector('.board-banner-card__meta') as HTMLElement
    expect(meta.textContent).toBe('轮次：第 1 / 5 轮')
  })

  it('renders only title and meta — no icons, bars, progress, or expert chips', () => {
    mounted = mountBoardBannerCard({ topic: '精简测试', maxRounds: 4, currentRound: 2 })
    // Only two child elements: __title and __meta
    const children = mounted.root.children
    expect(children.length).toBe(2)
    expect(children[0].className).toBe('board-banner-card__title')
    expect(children[1].className).toBe('board-banner-card__meta')
    // No icon elements, progress bars, or expert chips
    expect(mounted.root.querySelector('svg, .anticon, .board-banner-card__bar, .board-banner-card__progress, .board-banner-card__experts, .board-banner-card__chip')).toBeNull()
  })

  it('handles CJK topic correctly', () => {
    mounted = mountBoardBannerCard({ topic: '人工智能伦理边界探讨', maxRounds: 6 })
    const title = mounted.container.querySelector('.board-banner-card__title') as HTMLElement
    expect(title.textContent).toBe('私董会 — 人工智能伦理边界探讨')
  })

  it('handles empty topic gracefully', () => {
    mounted = mountBoardBannerCard({ topic: '', maxRounds: 5 })
    const title = mounted.container.querySelector('.board-banner-card__title') as HTMLElement
    expect(title.textContent).toBe('私董会 — ')
  })
})
