import { getDefaultProfileImage } from "@/lib/helpers";
import {
  dummyimg,
  dummyimg2,
  dummyimg4,
  type LeaderboardItem,
} from "./achievementsTypes";

/**
 * The three per-row readings the podium needs: avatar, display name, and the
 * profile route.
 *
 * Pure functions of the row (plus the board type and the translator), lifted
 * out of `LeaderboardPodium` so that component stays inside the 200-line
 * budget. Nothing about the values changed.
 */

/** The avatar to show, falling back to the gendered placeholder. */
export function podiumProfileImage(
  item: LeaderboardItem,
  type: string
): string {
  if (item.profile_pic) return item.profile_pic;
  if (type === "individuals") {
    return getDefaultProfileImage(
      item.gender_display?.value_en,
      dummyimg4,
      dummyimg,
      dummyimg2
    );
  }
  return dummyimg2;
}

/** Nickname, then real name, then organization name. */
export function podiumName(
  item: LeaderboardItem | null,
  t: (key: string) => string
): string {
  if (!item) return t("COMMON.NO_DATA");
  return (
    (item as { nickname?: string }).nickname ||
    item.name ||
    item.organization_name ||
    t("COMMON.NO_DATA")
  );
}

/** Where the row links — every profile is public (2026-10-18). */
export function podiumProfileHref(item: LeaderboardItem): string {
  return `/public-profile/${item.user_id || item.organization_id}`;
}
