'use client'; import { PropsWithChildren } from 'react'; import Link from 'next/link'; import { useParams, usePathname, useRouter } from 'next/navigation'; import { cn } from '@/lib/utils'; import Image from 'next/image'; import clsx from 'clsx'; import Img from '../ui/Img'; import { format } from 'date-fns'; import { cleanInputMessage } from '@/lib/messageUtils'; import { IconClose } from '../ui/Icons'; import { ChatWithMessages } from '@/lib/db/types'; import { dbDeleteChat } from '@/lib/db/functions'; type ChatCardProps = PropsWithChildren<{ chat: ChatWithMessages; isAdminView?: boolean; }>; export const ChatCardLayout: React.FC< PropsWithChildren<{ link: string; classNames?: clsx.ClassValue }> > = ({ link, children, classNames }) => { return ( {children} ); }; const ChatCard: React.FC = ({ chat, isAdminView }) => { const { id: chatIdFromParam } = useParams(); const { id, mediaUrl, messages, userId, updatedAt } = chat; if (!id) { return null; } const firstMessage = cleanInputMessage(messages?.[0]?.content ?? ''); const title = firstMessage ? firstMessage.length > 50 ? firstMessage.slice(0, 50) + '...' : firstMessage : '(No messages yet)'; return (
{`chat-${id}-card-image`}

{title}

{updatedAt ? format(Number(updatedAt), 'yyyy-MM-dd') : '-'}

{isAdminView &&

{userId}

} { e.stopPropagation(); await dbDeleteChat(id); }} className="absolute right-4 opacity-0 group-hover:opacity-100 top-1/2 -translate-y-1/2" />
); }; export default ChatCard;