/** Mirrors the API's password policy (change + reset password). */
export function passwordProblem(pw: string): string | null {
  if (pw.length < 8) return "At least 8 characters.";
  if (new TextEncoder().encode(pw).length > 72) return "At most 72 bytes.";
  if (!/[A-Z]/.test(pw)) return "Add an uppercase letter.";
  if (!/[a-z]/.test(pw)) return "Add a lowercase letter.";
  if (!/[0-9]/.test(pw)) return "Add a number.";
  if (!/[^A-Za-z0-9]/.test(pw)) return "Add a symbol.";
  return null;
}

export const PASSWORD_HINT = "8+ characters with an uppercase letter, a lowercase letter, a number and a symbol.";

/** Links the API accepts: http(s), /path, #anchor, mailto:, tel:. */
export const isLink = (s: string) => /^(https?:\/\/|\/|#|mailto:|tel:)/i.test(s.trim());
/** Media URLs the API accepts: http(s) or /path. */
export const isMediaUrl = (s: string) => /^(https?:\/\/|\/)/i.test(s.trim());
