'use client' import React, { useState } from 'react' import { DSRCommunication, CommunicationType, CommunicationChannel, DSRSendCommunicationRequest } from '@/lib/sdk/dsr/types' interface DSRCommunicationLogProps { communications: DSRCommunication[] onSendMessage?: (message: DSRSendCommunicationRequest) => Promise isLoading?: boolean } const CHANNEL_ICONS: Record = { email: 'M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z', letter: 'M3 19v-8.93a2 2 0 01.89-1.664l7-4.666a2 2 0 012.22 0l7 4.666A2 2 0 0121 10.07V19M3 19a2 2 0 002 2h14a2 2 0 002-2M3 19l6.75-4.5M21 19l-6.75-4.5M3 10l6.75 4.5M21 10l-6.75 4.5', phone: 'M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z', portal: 'M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9', internal_note: 'M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z' } const TYPE_COLORS: Record = { incoming: { bg: 'bg-blue-50', border: 'border-blue-200', icon: 'text-blue-600' }, outgoing: { bg: 'bg-green-50', border: 'border-green-200', icon: 'text-green-600' }, internal: { bg: 'bg-gray-50', border: 'border-gray-200', icon: 'text-gray-600' } } const CHANNEL_LABELS: Record = { email: 'E-Mail', letter: 'Brief', phone: 'Telefon', portal: 'Portal', internal_note: 'Interne Notiz' } function formatDate(dateString: string): string { const date = new Date(dateString) return date.toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }) } export function DSRCommunicationLog({ communications, onSendMessage, isLoading = false }: DSRCommunicationLogProps) { const [showComposeForm, setShowComposeForm] = useState(false) const [newMessage, setNewMessage] = useState({ type: 'outgoing', channel: 'email', subject: '', content: '' }) const [isSending, setIsSending] = useState(false) const sortedCommunications = [...communications].sort( (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ) const handleSendMessage = async () => { if (!onSendMessage || !newMessage.content.trim()) return setIsSending(true) try { await onSendMessage(newMessage) setNewMessage({ type: 'outgoing', channel: 'email', subject: '', content: '' }) setShowComposeForm(false) } catch (error) { console.error('Failed to send message:', error) } finally { setIsSending(false) } } return (
{/* Header */}

Kommunikation

{onSendMessage && ( )}
{/* Compose Form */} {showComposeForm && (
{newMessage.type !== 'internal' && (
setNewMessage({ ...newMessage, subject: e.target.value })} placeholder="Betreff eingeben..." className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500" />
)}