"use client"; import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { MessageSquare, Heart, Reply, MoreHorizontal, Send, User, ChevronDown, ChevronUp, Flag, Trash2, Edit } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { formatDistanceToNow } from "date-fns"; interface CommentUser { id: string; name: string; username: string; image?: string; rank?: string; } interface Comment { id: string; content: string; user: CommentUser; likes: number; liked?: boolean; createdAt: Date; replies?: Comment[]; } interface CommentsProps { promptId: string; comments?: Comment[]; currentUser?: CommentUser | null; } // Sample comments for demo const SAMPLE_COMMENTS: Comment[] = [ { id: "1", content: "This prompt is amazing! I've been using it for all my blog posts and the quality is incredible. Definitely recommend tweaking the tone variable for different audiences.", user: { id: "u1", name: "Sarah Chen", username: "sarahchen", image: "https://api.dicebear.com/7.x/avataaars/svg?seed=sarah", rank: "gold" }, likes: 24, liked: false, createdAt: new Date(Date.now() - 2 * 60 * 60 * 1000), replies: [ { id: "1-1", content: "Thanks for the tip! What tone setting works best for technical documentation?", user: { id: "u2", name: "Mike Johnson", username: "mikej", image: "https://api.dicebear.com/7.x/avataaars/svg?seed=mike", rank: "silver" }, likes: 8, createdAt: new Date(Date.now() - 1 * 60 * 60 * 1000), }, { id: "1-2", content: "For technical docs I use 'professional and precise'. Works great!", user: { id: "u1", name: "Sarah Chen", username: "sarahchen", image: "https://api.dicebear.com/7.x/avataaars/svg?seed=sarah", rank: "gold" }, likes: 12, createdAt: new Date(Date.now() - 30 * 60 * 1000), } ] }, { id: "2", content: "I remixed this with a few tweaks for SEO optimization. Check out my version if you're looking for better search rankings!", user: { id: "u3", name: "Alex Rivera", username: "alexr", image: "https://api.dicebear.com/7.x/avataaars/svg?seed=alex", rank: "verified" }, likes: 45, liked: true, createdAt: new Date(Date.now() - 24 * 60 * 60 * 1000), }, { id: "3", content: "Does this work well with Claude or is it optimized specifically for GPT-4?", user: { id: "u4", name: "Jordan Lee", username: "jordanl", image: "https://api.dicebear.com/7.x/avataaars/svg?seed=jordan", }, likes: 6, createdAt: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), }, ]; function RankBadge({ rank }: { rank?: string }) { if (!rank) return null; const colors: Record = { bronze: "bg-orange-900/50 text-orange-300 border-orange-700", silver: "bg-gray-700/50 text-gray-300 border-gray-600", gold: "bg-yellow-900/50 text-yellow-300 border-yellow-700", verified: "bg-blue-900/50 text-blue-300 border-blue-700", }; return ( {rank === "verified" ? "✓ Verified" : rank.charAt(0).toUpperCase() + rank.slice(1)} ); } function CommentItem({ comment, isReply = false, onReply, onLike, currentUser }: { comment: Comment; isReply?: boolean; onReply: (commentId: string) => void; onLike: (commentId: string) => void; currentUser?: CommentUser | null; }) { const [showReplies, setShowReplies] = useState(true); const [isLiked, setIsLiked] = useState(comment.liked || false); const [likesCount, setLikesCount] = useState(comment.likes); const handleLike = () => { if (isLiked) { setLikesCount(prev => prev - 1); } else { setLikesCount(prev => prev + 1); } setIsLiked(!isLiked); onLike(comment.id); }; return (
{comment.user.name} @{comment.user.username} · {formatDistanceToNow(comment.createdAt, { addSuffix: true })}

{comment.content}

{!isReply && ( )} {currentUser?.id === comment.user.id && ( <> Edit Delete )} Report
{/* Replies */} {comment.replies && comment.replies.length > 0 && (
{showReplies && ( {comment.replies.map((reply) => ( ))} )}
)}
); } export function Comments({ promptId, comments = SAMPLE_COMMENTS, currentUser }: CommentsProps) { const [newComment, setNewComment] = useState(""); const [replyingTo, setReplyingTo] = useState(null); const [allComments, setAllComments] = useState(comments); const handleSubmit = () => { if (!newComment.trim()) return; // In real app, this would be an API call const comment: Comment = { id: Date.now().toString(), content: newComment, user: currentUser || { id: "guest", name: "Guest User", username: "guest" }, likes: 0, createdAt: new Date(), }; if (replyingTo) { setAllComments(prev => prev.map(c => { if (c.id === replyingTo) { return { ...c, replies: [...(c.replies || []), comment] }; } return c; }) ); setReplyingTo(null); } else { setAllComments(prev => [comment, ...prev]); } setNewComment(""); }; const handleReply = (commentId: string) => { setReplyingTo(commentId); // Focus the textarea document.getElementById("comment-input")?.focus(); }; const handleLike = (commentId: string) => { // In real app, this would be an API call console.log("Liked comment:", commentId); }; return (

Comments ({allComments.length})

{/* Comment Input */}
{replyingTo && (
Replying to comment
)}