import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import ListingRow from '../components/listings/ListingRow'
import type { Listing } from '../lib/types'

const mockListing: Listing = {
  id: 1, title: 'RTX 4090 Gaming GPU', price: 299.99, currency: 'USD',
  price_raw: '$299.99', price_usd: 299.99, time_left: '2h 30m',
  time_left_mins: 150, link: 'https://example.com/lot/1', score: 30,
  keyword: 'RTX 4090', site_name: 'eBay UK', timestamp: '2026-03-11T10:00:00',
  price_updated_at: null, ai_match: 1, ai_reason: 'Matches RTX GPU target',
  location: 'London, UK', images: ['https://example.com/img1.jpg'],
  closing_alerts_sent: [],
}

vi.mock('../hooks/useCountdown', () => ({ useCountdown: () => () => 150 }))

describe('ListingRow', () => {
  it('renders title', () => {
    render(<table><tbody><ListingRow listing={mockListing} onSelect={vi.fn()} /></tbody></table>)
    expect(screen.getByText(/RTX 4090 Gaming GPU/)).toBeTruthy()
  })

  it('shows AI match badge', () => {
    render(<table><tbody><ListingRow listing={mockListing} onSelect={vi.fn()} /></tbody></table>)
    expect(screen.getByTitle(/AI match/i)).toBeTruthy()
  })

  it('shows score in gold', () => {
    render(<table><tbody><ListingRow listing={mockListing} onSelect={vi.fn()} /></tbody></table>)
    expect(screen.getByText('30')).toBeTruthy()
  })
})
