/**
 * (share/ui/badge — variants, asChild, badgeVariants).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import { Badge, badgeVariants } from '@/share/ui/badge'

jest.mock('radix-ui', () => ({
  Slot: {
    Root: ({ children, ...props }: { children: React.ReactNode; [k: string]: unknown }) =>
      React.isValidElement(children)
        ? React.cloneElement(children as React.ReactElement<Record<string, unknown>>, props)
        : <span {...props}>{children}</span>,
  },
}))

describe('[share/ui/badge]', () => {
  describe('Badge', () => {
    it('renders text', () => {
      render(<Badge>New</Badge>)
      expect(screen.getByText('New')).toBeInTheDocument()
    })

    it('applies variant and className', () => {
      render(
        <Badge variant="positive" className="custom-badge">
          Positive
        </Badge>,
      )

      const badge = screen.getByText('Positive')
      expect(badge).toHaveAttribute('data-variant', 'positive')
      expect(badge).toHaveClass('custom-badge')
    })

    it('supports asChild to merge props onto child link', () => {
      render(
        <Badge asChild>
          <a href="/">Link badge</a>
        </Badge>,
      )
      const link = screen.getByRole('link', { name: 'Link badge' })
      expect(link).toBeInTheDocument()
      expect(link).toHaveAttribute('data-variant', 'active')
    })
  })

  describe('badgeVariants', () => {
    it('maps variant keys to utility classes', () => {
      expect(badgeVariants({ variant: 'inactive' })).toContain('bg-grey-10')
      expect(badgeVariants({ variant: 'active' })).toContain('bg-green-2')
    })
  })
})
