import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

export function formatPhone(value: string): string {
  // Remove non-numeric characters
  const digits = value.replace(/\D/g, "");

  // Limit to 11 digits
  const limited = digits.substring(0, 11);

  // Apply mask
  if (limited.length <= 10) {
    // (xx) xxxx-xxxx
    return limited.replace(/(\d{2})(\d{4})(\d{0,4})/, "($1) $2-$3");
  } else {
    // (xx) xxxxx-xxxx
    return limited.replace(/(\d{2})(\d{5})(\d{0,4})/, "($1) $2-$3");
  }
}

