import { describe, it, expect } from 'vitest'
import React from 'react'
import { render } from '@testing-library/react-native'
import { VideoPlayer } from '@/src/shared/components/VideoPlayer'

describe('VideoPlayer rendering', () => {
  describe('preview mode', () => {
    it('renders gradient fallback when no videoUrl', () => {
      const { toJSON } = render(
        <VideoPlayer mode="preview" isPlaying={false} />
      )
      const tree = toJSON()
      expect(tree).toBeTruthy()
      expect(tree).toMatchSnapshot()
    })

    it('renders video view when videoUrl is provided', () => {
      const { toJSON } = render(
        <VideoPlayer
          videoUrl="https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8"
          mode="preview"
          isPlaying={true}
        />
      )
      const tree = toJSON()
      expect(tree).toBeTruthy()
      expect(tree).toMatchSnapshot()
    })

    it('renders with custom style', () => {
      const { toJSON } = render(
        <VideoPlayer
          mode="preview"
          style={{ height: 220, borderRadius: 20 }}
        />
      )
      expect(toJSON()).toMatchSnapshot()
    })

    it('renders with testID prop', () => {
      const { getByTestId } = render(
        <VideoPlayer
          mode="preview"
          testID="my-video-player"
        />
      )
      expect(getByTestId('my-video-player')).toBeTruthy()
    })
  })

  describe('background mode', () => {
    it('renders gradient fallback when no videoUrl', () => {
      const { toJSON } = render(
        <VideoPlayer mode="background" isPlaying={false} />
      )
      expect(toJSON()).toMatchSnapshot()
    })

    it('renders video view when videoUrl is provided', () => {
      const { toJSON } = render(
        <VideoPlayer
          videoUrl="https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8"
          mode="background"
          isPlaying={true}
        />
      )
      expect(toJSON()).toMatchSnapshot()
    })
  })

  describe('custom gradient colors', () => {
    it('renders with custom gradient colors when no video', () => {
      const { toJSON } = render(
        <VideoPlayer
          gradientColors={['#FF0000', '#0000FF']}
          mode="preview"
        />
      )
      expect(toJSON()).toMatchSnapshot()
    })
  })
})
