/**
 * The state of the "is this nickname free?" check.
 *
 * Six hooks declared this inline as `useState<{...}>` and five components
 * restated it in their props — one of them as `any`. The shape is identical in
 * every case, so it lives here once.
 *
 * `available` is tri-state on purpose: `null` means "not asked yet", which is
 * what keeps the form from showing a red cross before the user has typed.
 */
export interface NicknameAvailability {
  /** A request is in flight; the field shows a spinner. */
  checking: boolean;
  /** `null` until the first answer comes back. */
  available: boolean | null;
  /** Already localized by the backend. */
  message: string;
}

/**
 * The backend's `users.username` rule (`App\Support\Auth\Username`): 3–30
 * letters, digits or `_`, never digits only (an all-digit segment reads as a
 * user id on `public-profile/{id}`). Fixed once the account exists.
 */
export const USERNAME_PATTERN = /^(?=.*[A-Za-z_])[A-Za-z0-9_]{3,30}$/;

/** The state before anything has been typed. */
export const EMPTY_NICKNAME_AVAILABILITY: NicknameAvailability = {
  checking: false,
  available: null,
  message: "",
};
