// Copyright: © 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { useEffect, useRef } from 'react'; import { Hand, X as XIcon, Globe, Clock, MessageSquare } from 'lucide-react'; import { useTranslation } from '@/i18n/TranslationProvider'; import type { ConversationDetail as ConvDetail } from '../lib/types'; import { MessageBubble } from './MessageBubble'; import { StatusBadge } from './StatusBadge'; import { Composer } from './Composer'; import { RequestContactButton } from './RequestContactButton'; interface ConversationDetailProps { conversation: ConvDetail; onIntercept: () => void; onRelease: () => void; onSendOperatorMessage: (content: string) => void; } function formatRelative(date: Date | string, locale: string): string { const d = typeof date === 'string' ? new Date(date) : date; const diffMs = Date.now() - d.getTime(); const min = Math.floor(diffMs / 60_000); if (min < 1) return locale === 'de' ? 'gerade eben' : 'just now'; if (min < 60) return locale === 'de' ? `vor ${min} Min.` : `${min} min ago`; const hours = Math.floor(min / 60); if (hours < 24) return locale === 'de' ? `vor ${hours} Std.` : `${hours} h ago`; return d.toLocaleDateString(locale); } export function ConversationDetail({ conversation, onIntercept, onRelease, onSendOperatorMessage }: ConversationDetailProps) { const { t, locale } = useTranslation(); const transcriptEndRef = useRef(null); useEffect(() => { transcriptEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [conversation.messages.length]); const isIntercepted = conversation.status === 'intercepted'; const isClosed = conversation.status === 'closed'; const canIntercept = !isIntercepted && !isClosed; const composerHint = isIntercepted ? t('conversations.composer.interceptHint') : isClosed ? t('conversations.composer.closedHint') : t('conversations.composer.takeoverHint'); return (

{conversation.visitorRef}

{conversation.visitorLocale}
{conversation.pageUrlLast} {t('conversations.detail.messageCount', { count: conversation.messageCount })} {t('conversations.detail.lastActivity', { ago: formatRelative(conversation.lastActivityAt, locale) })}
{canIntercept && ( )} {isIntercepted && ( )}
{conversation.messages.map((msg) => ( ))}
); }