import { useEffect, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from "@/components/ui/card"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; import { useAuth } from "@/contexts/AuthContext"; import { useToast } from "@/hooks/use-toast"; import { communityService } from "@/lib/supabase-service"; import { Heart, MessageCircle, Share2, Volume2, VolumeX, MessageSquare } from "lucide-react"; import type { FeedItem } from "@/pages/Feed"; const DiscordIcon = () => ( ); const ARM_COLORS: Record< string, { bg: string; border: string; badge: string; text: string } > = { labs: { bg: "bg-yellow-500/10", border: "border-l-4 border-l-yellow-400", badge: "bg-yellow-500/20 text-yellow-200", text: "text-yellow-400", }, gameforge: { bg: "bg-green-500/10", border: "border-l-4 border-l-green-400", badge: "bg-green-500/20 text-green-200", text: "text-green-400", }, corp: { bg: "bg-blue-500/10", border: "border-l-4 border-l-blue-400", badge: "bg-blue-500/20 text-blue-200", text: "text-blue-400", }, foundation: { bg: "bg-red-500/10", border: "border-l-4 border-l-red-400", badge: "bg-red-500/20 text-red-200", text: "text-red-400", }, devlink: { bg: "bg-cyan-500/10", border: "border-l-4 border-l-cyan-400", badge: "bg-cyan-500/20 text-cyan-200", text: "text-cyan-400", }, nexus: { bg: "bg-purple-500/10", border: "border-l-4 border-l-purple-400", badge: "bg-purple-500/20 text-purple-200", text: "text-purple-400", }, staff: { bg: "bg-indigo-500/10", border: "border-l-4 border-l-indigo-400", badge: "bg-indigo-500/20 text-indigo-200", text: "text-indigo-400", }, }; const ARM_LABELS: Record = { labs: "LABS", gameforge: "GAMEFORGE", corp: "CORP", foundation: "FOUNDATION", devlink: "DEV-LINK", nexus: "NEXUS", staff: "STAFF", }; interface FeedItemCardProps { item: FeedItem; isFollowing: boolean; onToggleFollow: (authorId: string) => void; onShare: (postId: string) => void; onLike: (postId: string) => void; onComment: (postId: string) => void; } export function FeedItemCard({ item, isFollowing, onToggleFollow, onShare, onLike, onComment, }: FeedItemCardProps) { const [muted, setMuted] = useState(true); const [showComments, setShowComments] = useState(false); const [comments, setComments] = useState([]); const [loadingComments, setLoadingComments] = useState(false); const [commentText, setCommentText] = useState(""); const [submittingComment, setSubmittingComment] = useState(false); const { user } = useAuth(); const { toast } = useToast(); const hasMedia = item.mediaType !== "none" && Boolean(item.mediaUrl); useEffect(() => { if (!showComments) return; let cancelled = false; (async () => { setLoadingComments(true); try { const data = await communityService.listComments(item.id); if (!cancelled) setComments(Array.isArray(data) ? data : []); } finally { if (!cancelled) setLoadingComments(false); } })(); return () => { cancelled = true; }; }, [showComments, item.id]); const submitComment = async () => { if (!user?.id) { toast({ description: "Please sign in to comment." }); return; } const content = commentText.trim(); if (!content) return; setSubmittingComment(true); try { const created = await communityService.addComment( item.id, user.id, content, ); if (created) { setComments((prev) => [...prev, created]); setCommentText(""); onComment?.(item.id); } } catch (e) { toast({ variant: "destructive", description: "Failed to add comment" }); } finally { setSubmittingComment(false); } }; const armColor = ARM_COLORS[item.arm || "labs"] || ARM_COLORS.labs; const armLabel = ARM_LABELS[item.arm || "labs"] || "LABS"; return (
{item.authorName?.[0]?.toUpperCase() || "U"}
{item.authorName} {armLabel} {item.source === "discord" && ( {item.discordChannelName ? `#${item.discordChannelName}` : "Discord"} )}
{hasMedia && (
{item.mediaType === "video" ? ( <>
)} {item.caption && (

{item.caption}

)}
{item.mediaType === "video" ? "Video" : item.mediaType === "image" ? "Image" : "Update"}
{showComments && (
{loadingComments ? (

Loading comments…

) : comments.length === 0 ? (

Be the first to comment.

) : ( comments.map((c) => (
{(c.user_profiles?.full_name || c.user_profiles?.username || "U")[0]?.toUpperCase() || "U"}
{c.user_profiles?.full_name || c.user_profiles?.username || "Member"}
{c.content}
)) )}