/// Content rules for chat messages.
///
/// Links are not allowed in messages: it keeps the local-first, offline chat
/// free of phishing/scam URLs between people who may not know each other yet
/// (the web of trust is still forming). Enforced on send; incoming text is never
/// rendered as a tappable link either (the bubble uses plain selectable text).
library;

/// Matches an obvious URL: an explicit scheme, a `www.` host, or a
/// `domain.tld` with a common TLD. Kept deliberately conservative so ordinary
/// text ("3.5kg", "F1 hybrid") doesn't trip it, while real links do.
final RegExp _urlPattern = RegExp(
  r'(https?://|www\.)\S+'
  r'|\b[\w-]+\.(com|org|net|io|app|dev|es|eu|info|xyz|co|me|gg|link|shop|store|online|site|page|ru|cn|tk)\b',
  caseSensitive: false,
);

/// Whether [text] contains something that looks like a URL.
bool containsUrl(String text) => _urlPattern.hasMatch(text);
