/** * @file components/friends/PendingRequestsTab.tsx * @description Tab component that renders a list of pending friend requests with options to accept, decline, or cancel them. */ "use client"; import { Check, X } from "lucide-react"; import { UserAvatar } from "../ui/UserAvatar"; import { Friendship, FriendUser } from "./FriendsView"; /** * Properties for the PendingRequestsTab component. * * @interface PendingRequestsTabProps * @property {string} currentUserId - The unique identifier of the currently logged-in user. * @property {Friendship[]} pendingRequests - Array of pending friendship objects. * @property {(f: Friendship) => FriendUser} getFriendUser - Helper function to extract the friend user from a friendship record. * @property {(id: string) => void} onAccept - Callback function triggered to accept an incoming friend request. * @property {(id: string) => void} onDeclineOrCancel - Callback function triggered to decline an incoming request or cancel an outgoing one. */ interface PendingRequestsTabProps { currentUserId: string; pendingRequests: Friendship[]; getFriendUser: (f: Friendship) => FriendUser; onAccept: (id: string) => void; onDeclineOrCancel: (id: string) => void; } /** * Renders a list of pending friend requests with options to accept, decline, or cancel them. * * @param {PendingRequestsTabProps} props - The component props. * @param {string} props.currentUserId - The unique identifier of the currently logged-in user. * @param {Friendship[]} props.pendingRequests - Array of pending friendship objects. * @param {(f: Friendship) => FriendUser} props.getFriendUser - Helper function to extract the friend user. * @param {(id: string) => void} props.onAccept - Callback to accept a request. * @param {(id: string) => void} props.onDeclineOrCancel - Callback to decline or cancel a request. * @returns {JSX.Element} The rendered pending requests tab. */ export function PendingRequestsTab({ currentUserId, pendingRequests, getFriendUser, onAccept, onDeclineOrCancel, }: PendingRequestsTabProps) { return (

Pending Requests — {pendingRequests.length}

{pendingRequests.length === 0 ? (

No pending friend requests.

) : (
{pendingRequests.map((req) => { const isIncoming = req.receiverId === currentUserId; const friend = getFriendUser(req); return (
{friend.username}
{isIncoming ? "Incoming Request" : "Outgoing Request"}
{isIncoming && ( )}
); })}
)}
); }