import { createRef } from 'react'
import { describe, test, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { ChatAgentMessage } from './chat-agent-message'
import { ChatLoader } from '../feedback/chat-loader'
import { ChatThinking } from '../feedback/chat-thinking'

describe('ChatAgentMessage', () => {
  test('renders text as child', () => {
    render(<ChatAgentMessage>Agent response</ChatAgentMessage>)
    expect(screen.getByText('Agent response')).toBeTruthy()
  })

  test('forwards ref to the underlying element', () => {
    const ref = createRef<HTMLDivElement>()
    render(<ChatAgentMessage ref={ref}>Agent response</ChatAgentMessage>)
    expect(ref.current).toBeInstanceOf(HTMLElement)
  })

  test('renders ChatLoader as child', () => {
    const { container } = render(
      <ChatAgentMessage>
        <ChatLoader />
      </ChatAgentMessage>,
    )
    expect(container.querySelector('[role="status"]')).toBeTruthy()
  })

  test('renders ChatThinking as child', () => {
    render(
      <ChatAgentMessage>
        <ChatThinking>Processing...</ChatThinking>
      </ChatAgentMessage>,
    )
    expect(screen.getByText('Processing...')).toBeTruthy()
  })

  test('renders string children verbatim (no markdown)', () => {
    render(<ChatAgentMessage>{'Some **bold** text'}</ChatAgentMessage>)
    expect(screen.getByText('Some **bold** text')).toBeTruthy()
  })
})
