import { describe, it, expect } from 'vitest'
import { usePackageDisplay } from '@/composables/Packages/usePackageDisplay'

describe('usePackageDisplay', () => {
  const { repoName, repoVersion, getVersionColor, getStatusColor, getLto, getDs } =
    usePackageDisplay()

  describe('repoName', () => {
    it('should extract repo name from full repo string', () => {
      expect(repoName('extra-x86_64-v3')).toBe('extra')
      expect(repoName('core-x86_64-v4')).toBe('core')
    })
  })

  describe('repoVersion', () => {
    it('should extract version from full repo string', () => {
      expect(repoVersion('extra-x86_64-v3')).toBe('v3')
      expect(repoVersion('core-x86_64-v4')).toBe('v4')
    })
  })

  describe('getVersionColor', () => {
    it('should return CSS variable for v2', () => {
      expect(getVersionColor('v2')).toBe('var(--color-version-v2)')
    })

    it('should return CSS variable for v3', () => {
      expect(getVersionColor('v3')).toBe('var(--color-version-v3)')
    })

    it('should return CSS variable for v4', () => {
      expect(getVersionColor('v4')).toBe('var(--color-version-v4)')
    })

    it('should return muted color for unknown version', () => {
      expect(getVersionColor('v1')).toBe('var(--color-text-muted)')
      expect(getVersionColor('unknown')).toBe('var(--color-text-muted)')
    })
  })

  describe('getStatusColor', () => {
    it('should return empty string (status colors now handled by StatusBadge)', () => {
      expect(getStatusColor('skipped')).toBe('')
      expect(getStatusColor('queued')).toBe('')
      expect(getStatusColor('latest')).toBe('')
      expect(getStatusColor('failed')).toBe('')
      expect(getStatusColor('signing')).toBe('')
      expect(getStatusColor('building')).toBe('')
      expect(getStatusColor('unknown')).toBe('')
    })

    it('should return empty string for undefined status', () => {
      expect(getStatusColor(undefined)).toBe('')
    })
  })

  describe('getLto', () => {
    it('should return success info for enabled', () => {
      const result = getLto('enabled')
      expect(result.title).toBe('Built with LTO')
      expect(result.icon).toBe('mdi-check-circle')
      expect(result.color).toBe('var(--color-status-success)')
    })

    it('should return waiting info for unknown', () => {
      const result = getLto('unknown')
      expect(result.title).toBe('Not built with LTO yet')
      expect(result.icon).toBe('mdi-timer-sand')
      expect(result.color).toBe('var(--color-text-muted)')
    })

    it('should return error info for disabled', () => {
      const result = getLto('disabled')
      expect(result.title).toBe('LTO explicitly disabled')
      expect(result.icon).toBe('mdi-close-circle')
      expect(result.color).toBe('var(--color-status-error)')
    })

    it('should return warning info for auto_disabled', () => {
      const result = getLto('auto_disabled')
      expect(result.title).toBe('LTO automatically disabled')
      expect(result.icon).toBe('mdi-alert-circle')
      expect(result.color).toBe('var(--color-status-warning)')
    })

    it('should return empty for undefined', () => {
      const result = getLto(undefined)
      expect(result.title).toBe('')
      expect(result.icon).toBe('')
      expect(result.color).toBe('')
    })
  })

  describe('getDs', () => {
    it('should return success info for available', () => {
      const result = getDs('available')
      expect(result.title).toBe('Debug symbols available')
      expect(result.icon).toBe('mdi-check-circle')
      expect(result.color).toBe('var(--color-status-success)')
    })

    it('should return waiting info for unknown', () => {
      const result = getDs('unknown')
      expect(result.title).toBe('Not built yet')
      expect(result.icon).toBe('mdi-timer-sand')
      expect(result.color).toBe('var(--color-text-muted)')
    })

    it('should return error info for not_available', () => {
      const result = getDs('not_available')
      expect(result.title).toBe('Not built with debug symbols')
      expect(result.icon).toBe('mdi-close-circle')
      expect(result.color).toBe('var(--color-status-error)')
    })

    it('should return empty for undefined', () => {
      const result = getDs(undefined)
      expect(result.title).toBe('')
      expect(result.icon).toBe('')
      expect(result.color).toBe('')
    })
  })
})
