/**
 * Normalizes Iranian phone numbers to a standard format: 9120000001
 * Removes +98 prefix, leading 0, and any spaces/dashes
 * @param phone - The phone number to normalize
 * @returns Normalized phone number (e.g., 9120000001)
 */
export function normalizePhone(phone: string): string {
  if (!phone) {
    return phone;
  }

  // Remove all spaces, dashes, and parentheses
  let normalized = phone.replace(/[\s\-\(\)]/g, '');

  // Remove +98 prefix (Iran country code)
  if (normalized.startsWith('+98')) {
    normalized = normalized.substring(3);
  } else if (normalized.startsWith('0098')) {
    normalized = normalized.substring(4);
  } else if (normalized.startsWith('98')) {
    normalized = normalized.substring(2);
  }

  // Remove leading 0
  if (normalized.startsWith('0')) {
    normalized = normalized.substring(1);
  }

  return normalized;
}
