/** Legacy API values returned before i18n rollout */
const LEGACY_ONLINE_VALUES = new Set(["آنلاین", "Online"]);

export function isUserOnline(
  lastOnline?: string | null,
  onlineLabel?: string
): boolean {
  if (!lastOnline) return false;
  if (onlineLabel && lastOnline === onlineLabel) return true;
  return LEGACY_ONLINE_VALUES.has(lastOnline);
}

export function resolveOnlineLabel(
  lastOnline: string | undefined,
  onlineLabel: string,
  offlineLabel: string
): string {
  if (isUserOnline(lastOnline, onlineLabel)) return onlineLabel;
  return lastOnline || offlineLabel;
}
