"use client"; import React, { useState } from "react"; import { PostWithAuthor } from "@/lib/api"; import { ThumbsUp, MessageSquare, CheckCircle2, User } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; import { es } from "date-fns/locale"; interface PostCardProps { post: PostWithAuthor; onReply: (parentId: string) => void; onVote: (postId: string, voteType: 'upvote' | 'downvote') => void; onEndorse?: (postId: string) => void; depth: number; isInstructor?: boolean; } export default function PostCard({ post, onReply, onVote, onEndorse, depth, isInstructor }: PostCardProps) { const [isVoting, setIsVoting] = useState(false); const maxDepth = 5; // Limit nesting depth for UX const handleVote = async (voteType: 'upvote' | 'downvote') => { if (isVoting) return; setIsVoting(true); try { await onVote(post.id, voteType); } finally { setIsVoting(false); } }; const indentClass = depth > 0 ? `ml-${Math.min(depth * 4, 16)} pl-4 border-l-2 border-white/10` : ''; return (
0 ? 'mt-4' : 'mt-6'}`} aria-labelledby={`post-content-${post.id}`} >
{/* Header */}
{/* Avatar */} {/* Author Info */}
{post.author_name} {post.is_endorsed && ( Respuesta Correcta )} {formatDistanceToNow(new Date(post.created_at), { addSuffix: true, locale: es })}
{/* Content */}
{post.content}
{/* Actions */}
{/* Upvote Button */} {/* Reply Button */} {depth < maxDepth && ( )} {/* Endorse Button (Instructor Only) */} {isInstructor && onEndorse && ( )}
{/* Nested Replies */} {post.replies && post.replies.length > 0 && (
{post.replies.map((reply) => ( ))}
)}
); }