export const publicFormErrorMessage =
  "We could not send this just now. Please check the details and try again, or email MPC directly.";

const technicalWords = [
  "api",
  "smtp",
  "database",
  "mysql",
  "sql",
  "token",
  "route",
  "lead",
  "admin",
  "json",
  "webhook",
  "server",
  "stack",
  "object",
  "undefined",
  "null",
  "failed",
  "exception",
];

export function visitorSafeMessage(value: unknown, fallback = publicFormErrorMessage) {
  const message = typeof value === "string" ? value.trim() : "";

  if (!message || message.length > 180) return fallback;
  if (technicalWords.some((word) => message.toLowerCase().includes(word))) return fallback;

  return message;
}

export function visitorEmailFallbackLabel() {
  return "Open email copy";
}
