import { describe, it, expect } from 'vitest'

type FontWeight = 'regular' | 'medium' | 'semibold' | 'bold'

const WEIGHT_MAP: Record<FontWeight, string> = {
  regular: '400',
  medium: '500',
  semibold: '600',
  bold: '700',
}

describe('StyledText', () => {
  describe('weight mapping', () => {
    it('should map regular to 400', () => {
      expect(WEIGHT_MAP['regular']).toBe('400')
    })

    it('should map medium to 500', () => {
      expect(WEIGHT_MAP['medium']).toBe('500')
    })

    it('should map semibold to 600', () => {
      expect(WEIGHT_MAP['semibold']).toBe('600')
    })

    it('should map bold to 700', () => {
      expect(WEIGHT_MAP['bold']).toBe('700')
    })
  })

  describe('default values', () => {
    it('should have default size of 17', () => {
      const defaultSize = 17
      expect(defaultSize).toBe(17)
    })

    it('should have default weight of regular', () => {
      const defaultWeight: FontWeight = 'regular'
      expect(WEIGHT_MAP[defaultWeight]).toBe('400')
    })
  })

  describe('style computation', () => {
    const computeTextStyle = (size: number, weight: FontWeight, color: string) => ({
      fontSize: size,
      fontWeight: WEIGHT_MAP[weight],
      color,
    })

    it('should compute correct style with defaults', () => {
      const style = computeTextStyle(17, 'regular', '#FFFFFF')
      expect(style.fontSize).toBe(17)
      expect(style.fontWeight).toBe('400')
      expect(style.color).toBe('#FFFFFF')
    })

    it('should compute correct style with custom size', () => {
      const style = computeTextStyle(24, 'regular', '#FFFFFF')
      expect(style.fontSize).toBe(24)
    })

    it('should compute correct style with bold weight', () => {
      const style = computeTextStyle(17, 'bold', '#FFFFFF')
      expect(style.fontWeight).toBe('700')
    })

    it('should compute correct style with custom color', () => {
      const style = computeTextStyle(17, 'regular', '#FF0000')
      expect(style.color).toBe('#FF0000')
    })

    it('should compute correct style with all custom props', () => {
      const style = computeTextStyle(20, 'semibold', '#5AC8FA')
      expect(style.fontSize).toBe(20)
      expect(style.fontWeight).toBe('600')
      expect(style.color).toBe('#5AC8FA')
    })
  })

  describe('numberOfLines handling', () => {
    it('should accept numberOfLines prop', () => {
      const numberOfLines = 2
      expect(numberOfLines).toBe(2)
    })

    it('should handle undefined numberOfLines', () => {
      const numberOfLines: number | undefined = undefined
      expect(numberOfLines).toBeUndefined()
    })
  })

  describe('style merging', () => {
    const mergeStyles = (baseStyle: object, customStyle: object | undefined) => {
      return customStyle ? [baseStyle, customStyle] : [baseStyle]
    }

    it('should merge custom style with base style', () => {
      const base = { fontSize: 17, fontWeight: '400' }
      const custom = { marginTop: 10 }
      const merged = mergeStyles(base, custom)
      
      expect(merged).toHaveLength(2)
      expect(merged[0]).toEqual(base)
      expect(merged[1]).toEqual(custom)
    })

    it('should return only base style when no custom style', () => {
      const base = { fontSize: 17, fontWeight: '400' }
      const merged = mergeStyles(base, undefined)
      
      expect(merged).toHaveLength(1)
      expect(merged[0]).toEqual(base)
    })
  })

  describe('theme color integration', () => {
    const mockThemeColors = {
      text: {
        primary: '#FFFFFF',
        secondary: '#8E8E93',
        tertiary: '#636366',
      },
    }

    it('should use primary text color as default', () => {
      const defaultColor = mockThemeColors.text.primary
      expect(defaultColor).toBe('#FFFFFF')
    })

    it('should allow color override', () => {
      const customColor = '#FF0000'
      const resolvedColor = customColor || mockThemeColors.text.primary
      expect(resolvedColor).toBe('#FF0000')
    })

    it('should fallback to theme color when no override', () => {
      const customColor: string | undefined = undefined
      const resolvedColor = customColor || mockThemeColors.text.primary
      expect(resolvedColor).toBe('#FFFFFF')
    })
  })
})
