export function sanitizeText(value: string) {
  return value.trim();
}

export function sanitizeMessage(value: string) {
  // Allow only alphanumeric, spaces, underscores, newlines, and basic punctuation
  // Remove any HTML tags, scripts, and dangerous characters
  return value
    .trim()
    .replace(/<[^>]*>/g, '') // Remove HTML tags
    .replace(/[^\w\s\n\r_.,!?'-]/g, '') // Keep only safe characters
    .slice(0, 5000); // Limit length
}

export interface PasswordRequirement {
  name: string;
  met: boolean;
}

export function getPasswordRequirements(value: string): PasswordRequirement[] {
  return [
    {
      name: "8-20 Characters",
      met: value.length >= 8 && value.length <= 20,
    },
    {
      name: "At least one capital letter",
      met: /[A-Z]/.test(value),
    },
    {
      name: "At least one number",
      met: /\d/.test(value),
    },
    {
      name: "No spaces",
      met: !/\s/.test(value),
    },
  ];
}

export function isStrongPassword(value: string) {
  // 8-20 chars, at least one uppercase, at least one number, no spaces
  return /^(?=.*[A-Z])(?=.*\d)[A-Za-z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{8,20}$/.test(value) && !/\s/.test(value);
}

