/**
 * Who may see Billing and buy routes or permits (Nash, 2026-10-01).
 *
 * "Only admin to have the billing and the buttons to buy routes or to buy
 * permits. Only user role admin. And let's say user role moderator also for
 * now… From any terminal, any other user should not have the ability to do
 * that."
 *
 * - admin: the account role, or an admin who switched into a test account
 *   (`internal`) so the purchase flow can still be rehearsed.
 * - moderator: there is no moderator account role; a moderator is a person
 *   granted at least one moderator page (`surfaces`, migration 0032).
 *
 * ONE rule for every surface: the app shell hands it to the screens, and the
 * purchase guards on the server refuse everyone else. To open purchasing to
 * customers later, change this function only.
 */
export function canUsePurchasing(
  user: { role?: string | null; internal?: boolean; surfaces?: string[] } | null | undefined,
): boolean {
  if (!user) return false
  if (user.role === 'admin' || user.internal === true) return true
  return (user.surfaces?.length ?? 0) > 0
}

export const PURCHASING_NOT_AVAILABLE = 'Purchasing is not available on this account.'
