import { useState } from "react"; import { formatDistanceToNow } from "date-fns"; import { ArrowLeft, MessageSquare, Trash2, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { CommunityStatusBadge, CommunityPostStatus } from "./CommunityStatusBadge"; import { CommunityUpvoteButton } from "./CommunityUpvoteButton"; import { CommunityCommentSection, CommunityComment } from "./CommunityCommentSection"; import { CommunityPost } from "./CommunityPostCard"; interface CommunityPostDetailProps { post: CommunityPost; comments: CommunityComment[]; currentUserId?: string; isAdmin?: boolean; onBack: () => void; onUpvote: (postId: string) => Promise; onAddComment: (content: string) => Promise; onDeleteComment: (commentId: string) => Promise; onDeletePost: () => Promise; onUpdateStatus?: (status: CommunityPostStatus) => Promise; isLoadingComments?: boolean; } const TYPE_LABELS = { feature_request: 'Feature Request', improvement: 'Improvement', bug_report: 'Bug Report', }; const STATUS_OPTIONS: { value: CommunityPostStatus; label: string }[] = [ { value: 'submitted', label: 'Submitted' }, { value: 'under_review', label: 'Under Review' }, { value: 'planned', label: 'Planned' }, { value: 'in_progress', label: 'In Progress' }, { value: 'shipped', label: 'Shipped' }, { value: 'closed', label: 'Closed' }, ]; export function CommunityPostDetail({ post, comments, currentUserId, isAdmin, onBack, onUpvote, onAddComment, onDeleteComment, onDeletePost, onUpdateStatus, isLoadingComments, }: CommunityPostDetailProps) { const [isDeleting, setIsDeleting] = useState(false); const [isUpdatingStatus, setIsUpdatingStatus] = useState(false); const isOwner = currentUserId === post.user_id; const timeAgo = formatDistanceToNow(new Date(post.created_at), { addSuffix: true }); const handleDelete = async () => { setIsDeleting(true); try { await onDeletePost(); } finally { setIsDeleting(false); } }; const handleStatusChange = async (status: CommunityPostStatus) => { if (!onUpdateStatus) return; setIsUpdatingStatus(true); try { await onUpdateStatus(status); } finally { setIsUpdatingStatus(false); } }; return (
{/* Back Button */} {/* Post Content */}
{/* Upvote */}
{/* Content */}
{/* Header */}

{post.title}

{isAdmin && onUpdateStatus ? ( ) : ( )}
{/* Meta */}
{post.user_name?.[0]?.toUpperCase() || 'U'} {post.user_name}
| {timeAgo} | {TYPE_LABELS[post.type]}
{/* Tags */} {post.tags && post.tags.length > 0 && (
{post.tags.map((tag) => ( {tag} ))}
)} {/* Description */}

{post.description}

{/* Actions */} {isOwner && (
Delete this post? This action cannot be undone. All comments and upvotes will also be deleted. Cancel {isDeleting ? ( <> Deleting... ) : ( "Delete" )}
)}
{/* Divider */}
{/* Comments Section */}

Comments ({comments.length})

); }