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

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

/**
 * Sanitize user input before interpolating into AI prompts.
 * Strips newlines, special control characters, and limits length.
 */
export function sanitizePromptInput(input: string, maxLength = 200): string {
  return input
    .replace(/[\n\r\t]/g, ' ')           // Replace newlines/tabs with spaces
    .replace(/[^\w\s.,'-]/g, '')          // Strip special chars, keep alphanumeric + basic punctuation
    .replace(/\s+/g, ' ')                 // Collapse multiple spaces
    .trim()
    .slice(0, maxLength);
}
