import { describe, it, expect, vi } from 'vitest'
import { unixTimestampToLocalizedDate, useRelativeTime } from '@/composables/useDateFormat'

describe('useDateFormat', () => {
  describe('unixTimestampToLocalizedDate', () => {
    it('should convert unix timestamp to localized date string', () => {
      // Mock navigator.language
      vi.stubGlobal('navigator', { language: 'en-US' })

      const timestamp = 1702612991 // 2023-12-15T03:43:11Z
      const result = unixTimestampToLocalizedDate(timestamp)

      // The exact format depends on locale, but it should be a string
      expect(typeof result).toBe('string')
      expect(result.length).toBeGreaterThan(0)
    })

    it('should handle timestamp 0', () => {
      const result = unixTimestampToLocalizedDate(0)
      expect(typeof result).toBe('string')
    })
  })

  describe('useRelativeTime', () => {
    it('should format seconds correctly', () => {
      const { formatTimeAgo } = useRelativeTime()

      const result = formatTimeAgo(30)
      expect(result).toContain('30')
      expect(result).toContain('second')
    })

    it('should format minutes correctly', () => {
      const { formatTimeAgo } = useRelativeTime()

      const result = formatTimeAgo(120) // 2 minutes
      expect(result).toContain('2')
      expect(result).toContain('minute')
    })

    it('should format hours correctly', () => {
      const { formatTimeAgo } = useRelativeTime()

      const result = formatTimeAgo(7200) // 2 hours
      expect(result).toContain('2')
      expect(result).toContain('hour')
    })

    it('should use minutes for values between 60 and 3600 seconds', () => {
      const { formatTimeAgo } = useRelativeTime()

      const result = formatTimeAgo(180) // 3 minutes
      expect(result).toContain('minute')
      expect(result).not.toContain('second')
    })

    it('should use hours for values >= 3600 seconds', () => {
      const { formatTimeAgo } = useRelativeTime()

      const result = formatTimeAgo(3600) // 1 hour
      expect(result).toContain('hour')
      expect(result).not.toContain('minute')
    })
  })
})
