"use client"; import { Check, Copy, ExternalLink, MessageSquare, Trash2 } from "lucide-react"; import Image from "next/image"; import { useCallback, useRef, useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import type { PublicChatSnapshotDetail } from "@/contracts/types/chat-threads.types"; import { useMediaQuery } from "@/hooks/use-media-query"; function getInitials(name: string): string { const parts = name.trim().split(/\s+/); if (parts.length >= 2) { return (parts[0][0] + parts[1][0]).toUpperCase(); } return name.slice(0, 2).toUpperCase(); } interface PublicChatSnapshotRowProps { snapshot: PublicChatSnapshotDetail; canDelete: boolean; onCopy: (snapshot: PublicChatSnapshotDetail) => void; onDelete: (snapshot: PublicChatSnapshotDetail) => void; isDeleting?: boolean; memberMap: Map; } export function PublicChatSnapshotRow({ snapshot, canDelete, onCopy, onDelete, isDeleting = false, memberMap, }: PublicChatSnapshotRowProps) { const [copied, setCopied] = useState(false); const copyTimeoutRef = useRef>(null); const isDesktop = useMediaQuery("(min-width: 768px)"); const handleCopyClick = useCallback(() => { onCopy(snapshot); setCopied(true); if (copyTimeoutRef.current) clearTimeout(copyTimeoutRef.current); copyTimeoutRef.current = setTimeout(() => setCopied(false), 2000); }, [onCopy, snapshot]); const formattedDate = new Date(snapshot.created_at).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric", }); const member = snapshot.created_by_user_id ? memberMap.get(snapshot.created_by_user_id) : null; return ( {/* Header: Title + Actions */}

{snapshot.thread_title}

Open link {canDelete && ( Delete )}
{/* Message count badge */}
{snapshot.message_count} messages
{/* Public URL – selectable fallback for manual copy */}

{snapshot.public_url}

{copied ? "Copied!" : "Copy link"}
{/* Footer: Date + Creator */}
{formattedDate} {member && ( <> ·
{member.avatarUrl ? ( {member.name} ) : (
{getInitials(member.name)}
)} {member.name}
{member.email || member.name}
)}
); }