export function phoneLookupVariants(value: string): string[] {
  const trimmed = value.trim();
  const digits = trimmed.replace(/\D/g, '');
  const variants = new Set<string>([trimmed, digits]);

  if (digits.length === 11 && digits.startsWith('8')) {
    const normalized = `7${digits.slice(1)}`;
    variants.add(normalized);
    variants.add(`+${normalized}`);
  } else if (digits.length === 11 && digits.startsWith('7')) {
    variants.add(`+${digits}`);
    variants.add(`8${digits.slice(1)}`);
  } else if (digits.length === 10) {
    variants.add(`7${digits}`);
    variants.add(`+7${digits}`);
  }

  if (trimmed.startsWith('+') && digits) {
    variants.add(`+${digits}`);
  }

  return [...variants];
}

export function canonicalPhoneE164(value: string): string {
  const digits = value.replace(/\D/g, '');
  if (!digits) {
    return value.trim();
  }

  let normalized = digits;
  if (normalized.length === 11 && normalized.startsWith('8')) {
    normalized = `7${normalized.slice(1)}`;
  } else if (normalized.length === 10) {
    normalized = `7${normalized}`;
  }

  return `+${normalized}`;
}
