import { format, formatDistanceToNow } from 'date-fns'

export const formatCurrency = (amount: string | number): string => {
  const num = typeof amount === 'string' ? parseFloat(amount) : amount
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
  }).format(num)
}

export const formatDate = (date: string): string => {
  return format(new Date(date), 'MMM d, yyyy')
}

export const formatDateTime = (date: string): string => {
  return format(new Date(date), 'MMM d, yyyy h:mm a')
}

export const formatRelativeTime = (date: string): string => {
  return formatDistanceToNow(new Date(date), { addSuffix: true })
}

export const formatPercentage = (value: number): string => {
  return `${(value * 100).toFixed(1)}%`
}
