"use client"; import { useState } from "react"; import { UserMinus, UserPlus } from "lucide-react"; import { followUser, unfollowUser, RemoteActor, Thought, Me } from "@/lib/api"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { ThoughtList } from "@/components/thought-list"; import { toast } from "sonner"; import { useAuth } from "@/hooks/use-auth"; import { ProfileCard } from "./profile-card"; import { Connections } from "./connections"; interface RemoteUserProfileProps { actor: RemoteActor; initialPosts: Thought[]; me: Me | null; initialFollowed?: boolean; } export function RemoteUserProfile({ actor, initialPosts, me, initialFollowed = false, }: RemoteUserProfileProps) { const [followed, setFollowed] = useState(initialFollowed); const [followLoading, setFollowLoading] = useState(false); const { token } = useAuth(); type ConnectionTab = "posts" | "followers" | "following"; const [activeTab, setActiveTab] = useState("posts"); const [followersActive, setFollowersActive] = useState(false); const [followingActive, setFollowingActive] = useState(false); const handleFollow = async () => { if (!token) { toast.error("You must be logged in to follow users."); return; } setFollowLoading(true); try { if (followed) { await unfollowUser(actor.handle, token); setFollowed(false); } else { await followUser(actor.handle, token); setFollowed(true); toast.success(`Follow request sent to ${actor.handle}`); } } catch { toast.error(followed ? "Failed to unfollow." : "Failed to send follow request."); } finally { setFollowLoading(false); } }; const handleTabChange = (tab: string) => { setActiveTab(tab as ConnectionTab); if (tab === "followers") setFollowersActive(true); if (tab === "following") setFollowingActive(true); }; const isOwnProfile = me?.username === actor.handle; const followButton = !isOwnProfile && token ? ( ) : undefined; return (
Posts Followers Following {initialPosts.length > 0 ? ( ) : (

Posts are being fetched — check back soon.

)}
); }