import { formatCurrency } from '@rentaldrivego/types'
import type { CarplaceLanguage, OfferSummary } from './types'

export function formatOfferValue(offer: OfferSummary, language: CarplaceLanguage): string {
  if (offer.type === 'FIXED_AMOUNT') return formatCurrency(offer.discountValue, 'MAD', language)
  if (offer.type === 'FREE_DAY') {
    const days = Math.max(1, offer.discountValue)
    if (language === 'ar') return `${days} ${days === 1 ? 'يوم مجاني' : 'أيام مجانية'}`
    if (language === 'fr') return `${days} ${days === 1 ? 'jour offert' : 'jours offerts'}`
    return `${days} ${days === 1 ? 'free day' : 'free days'}`
  }
  if (offer.type === 'SPECIAL_RATE') {
    const rate = offer.specialRate ?? offer.discountValue
    const suffix = language === 'ar' ? '/يوم' : language === 'fr' ? '/jour' : '/day'
    return `${formatCurrency(rate, 'MAD', language)}${suffix}`
  }
  return `${offer.discountValue}%`
}
