/**
 * The achievements screen's shapes, and the placeholder images its leaderboards
 * fall back to.
 *
 * The three avatar placeholders are chosen by the account's gender, which is
 * why there are three rather than one.
 */

export type LeaderboardType = "individuals" | "teams" | "companies";

/**
 * One row of any of the three leaderboards.
 *
 * Deliberately a merged shape rather than a union: the row components read
 * `name` *or* `organization_name` and `total_hours` *or*
 * `executed_opportunities` *or* `sponsored_count` from the same props, so the
 * keys the other boards do not send are optional. The precise per-board shapes
 * are `TopIndividual` and `TopOrganization` in
 * `features/achievements/statisticsRecord.ts`.
 *
 * Corrections over the previous declaration: `user_id` and `organization_id`
 * are **integers** (`$row->user_id`, `$team->user_id`), `profile_pic` is
 * nullable, `badge_info` and `gender_display` are nullable rather than merely
 * absent, and `user_type` is not a closed two-value union — the controller
 * emits `$user->user_type?->value` with a string default, and `UserType` also
 * has an `admin` case.
 */
export interface LeaderboardItem {
  /** Competition rank from the backend — ties share a number (1, 1, 3). */
  rank?: number;
  user_id?: number;
  organization_id?: number;
  name?: string;
  organization_name?: string;
  profile_pic?: string | null;
  total_hours?: number;
  /** Individuals: `total_hours` as H:MM (`HoursFormat::fromHours`). */
  total_hours_display?: string;
  executed_opportunities?: number;
  sponsored_count?: number;
  /** Companies: completed opportunities + sponsorships — what they are ranked by. */
  total_score?: number;
  gender_display?: { value_en?: string; value_ar?: string } | null;
  user_type?: string;
  is_public?: boolean;
  badge_info?: { id: number; name: string } | null;
}

export interface LeaderboardPodiumProps {
  /* The *input* is never sparse — the nulls are padding the component adds
     itself when fewer than three rows came back. Undefined until the fetch
     resolves, which the `data || []` inside already handles. */
  data?: LeaderboardItem[];
  type: LeaderboardType;
  t: (key: string) => string;
}

export interface LeaderboardTableProps {
  /* Undefined until the fetch resolves; the component already returns null
     for a list of three or fewer. */
  data?: LeaderboardItem[];
  type: LeaderboardType;
  startRank?: number;
  t: (key: string) => string;
}

export interface AchievementSectionProps {
  title: string;
  /* `| undefined`: the three arrays come off a response that is undefined
     until the fetch resolves, and both the podium and the table already
     return null for an empty or short list. */
  data?: LeaderboardItem[];
  type: LeaderboardType;
  t: (key: string) => string;
}

/**
 * One row of the leaderboard *table* (ranks 4 and below).
 *
 * An alias: this was a byte-identical copy of `LeaderboardItem`, declared
 * separately and drifting in lockstep. The podium and the table render the
 * same rows from the same three arrays.
 */
export type TableItem = LeaderboardItem;

export const dummyimg = "/assets/profile/female_profile.svg";
export const dummyimg2 = "/assets/profile/org_profile.svg";
export const dummyimg4 = "/assets/profile/male_profile.svg";
export const img2 = "/assets/achivments/i1.svg";
