import Link from "next/link"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { UserAvatar } from "./user-avatar"; import { getUserProfile, User } from "@/lib/api"; import { cookies } from "next/headers"; interface TopFriendsProps { mode: "friends" | "top-friends"; usernames: string[]; } export async function TopFriends({ mode = "top-friends", usernames, }: TopFriendsProps) { const token = (await cookies()).get("auth_token")?.value ?? null; if (usernames.length === 0) { return ( Top Friends

No top friends to display.

); } const friendsResults = await Promise.allSettled( usernames.map((username) => getUserProfile(username, token)) ); const friends = friendsResults .filter( (result): result is PromiseFulfilledResult => result.status === "fulfilled" ) .map((result) => result.value); return ( {mode === "top-friends" ? "Top Friends" : "Friends"} {friends.map((friend) => ( {friend.displayName || friend.username} ))} ); }