import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; import Card from "../card"; import CountryFlag from "../country-flag"; import { Avatar, AvatarImage } from "../ui/avatar"; import ClaimProfile from "./claim-profile"; import PlayerStats from "./player-stats"; import Tooltip from "@/components/tooltip"; import { ReactElement } from "react"; import PlayerTrackedStatus from "@/components/player/player-tracked-status"; import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player"; import Link from "next/link"; /** * Renders the change for a stat. * * @param change the amount of change * @param tooltip the tooltip to display * @param format the function to format the value */ const renderChange = (change: number, tooltip: ReactElement, format?: (value: number) => string) => { format = format ?? formatNumberWithCommas; return (

0 ? "text-green-400" : "text-red-400"}`}> {change > 0 ? "+" : ""} {format(change)}

); }; const playerData = [ { showWhenInactiveOrBanned: false, icon: () => { return ; }, render: (player: ScoreSaberPlayer) => { const statisticChange = player.statisticChange; const rankChange = statisticChange?.rank ?? 0; return (

#{formatNumberWithCommas(player.rank)}

{rankChange != 0 && renderChange(rankChange,

The change in your rank compared to yesterday

)}
); }, }, { showWhenInactiveOrBanned: false, icon: (player: ScoreSaberPlayer) => { return ; }, render: (player: ScoreSaberPlayer) => { const statisticChange = player.statisticChange; const rankChange = statisticChange?.countryRank ?? 0; return (

#{formatNumberWithCommas(player.countryRank)}

{rankChange != 0 && renderChange(rankChange,

The change in your country rank compared to yesterday

)}
); }, }, { showWhenInactiveOrBanned: true, render: (player: ScoreSaberPlayer) => { const statisticChange = player.statisticChange; const ppChange = statisticChange?.pp ?? 0; return (

{formatPp(player.pp)}pp

{ppChange != 0 && renderChange(ppChange,

The change in your pp compared to yesterday

, number => { return `${formatPp(number)}pp`; })}
); }, }, ]; type Props = { player: ScoreSaberPlayer; }; export default function PlayerHeader({ player }: Props) { return (

{player.name}

{player.inactive &&

Inactive Account

} {player.banned &&

Banned Account

}
{playerData.map((subName, index) => { // Check if the player is inactive or banned and if the data should be shown if (!subName.showWhenInactiveOrBanned && (player.inactive || player.banned)) { return null; } return (
{subName.icon && subName.icon(player)} {subName.render && subName.render(player)}
); })}
); }