/**
 * Formats a phone number to the standard Brazilian format: (11) 99999-9999
 */
export function formatPhone(value: string): string {
  const cleaned = value.replace(/\D/g, '').slice(0, 11)

  if (cleaned.length === 0) return ''
  if (cleaned.length <= 2) return cleaned
  if (cleaned.length <= 7) return `(${cleaned.slice(0, 2)}) ${cleaned.slice(2)}`
  return `(${cleaned.slice(0, 2)}) ${cleaned.slice(2, 7)}-${cleaned.slice(7)}`
}

/**
 * Removes phone formatting, returning only digits
 */
export function removePhoneFormatting(phone: string): string {
  return phone.replace(/\D/g, '')
}
