"use client"; import { Card, CardContent, CardFooter, CardHeader, } from "@/components/ui/card"; import { UserAvatar } from "./user-avatar"; import { deleteThought, Me, Thought } from "@/lib/api"; import { formatDistanceToNow } from "date-fns"; import { useAuth } from "@/hooks/use-auth"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { CornerUpLeft, MessageSquare, MoreHorizontal, Trash2, } from "lucide-react"; import { ReplyForm } from "@/components/reply-form"; import Link from "next/link"; interface ThoughtCardProps { thought: Thought; author: { username: string; avatarUrl?: string | null; }; currentUser: Me | null; isReply?: boolean; } export function ThoughtCard({ thought, author, currentUser, isReply = false, }: ThoughtCardProps) { const [isAlertOpen, setIsAlertOpen] = useState(false); const [isReplyOpen, setIsReplyOpen] = useState(false); const { token } = useAuth(); const router = useRouter(); const timeAgo = formatDistanceToNow(new Date(thought.createdAt), { addSuffix: true, }); const isAuthor = currentUser?.username === thought.authorUsername; const handleDelete = async () => { if (!token) return; try { await deleteThought(thought.id, token); toast.success("Thought deleted successfully."); router.refresh(); } catch (error) { console.error("Failed to delete thought:", error); toast.error("Failed to delete thought."); } finally { setIsAlertOpen(false); } }; return ( <>
{thought.content}