/** * AccordionChatItem - TASK-043 * * Chat item with expandable accordion showing participants. * - Click on chat → opens the chat * - Click on expand → shows all participants */ import { useState } from 'react'; import { ChevronDown, User, Bot, Users, Trash2, Link2 } from 'lucide-react'; import { cn } from '@/shared/utils/cn'; // Types interface ChatParticipant { user_id: number; name: string; email?: string; avatar_url?: string; role?: string; user_type?: string; } interface ChatConversation { id: number; title: string; type: string; agentIcon?: string; agentName?: string; messagesCount: number; updatedAt: string; participants?: ChatParticipant[]; space_id?: number; spaceName?: string; /** Bound row label, e.g. "Tickets #123" */ boundRowLabel?: string; } interface AccordionChatItemProps { conversation: ChatConversation; isActive: boolean; onSelect: (id: number) => void; onDelete: (id: number) => void; } export function AccordionChatItem({ conversation, isActive, onSelect, onDelete, }: AccordionChatItemProps) { const [isExpanded, setIsExpanded] = useState(false); const participants = conversation.participants || []; const participantCount = participants.length; const handleExpandClick = (e: React.MouseEvent) => { e.stopPropagation(); setIsExpanded(!isExpanded); }; const formatDate = (dateStr: string) => { const date = new Date(dateStr); const now = new Date(); const diffDays = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60 * 24)); if (diffDays === 0) { return date.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' }); } else if (diffDays === 1) { return 'Вчера'; } else if (diffDays < 7) { return date.toLocaleDateString('ru-RU', { weekday: 'short' }); } else { return date.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' }); } }; return (
{/* Main row */}
{/* Click area for selecting chat */} {/* Date */} {formatDate(conversation.updatedAt)} {/* Expand button - shows participant count */} {participantCount > 0 && ( )} {/* Delete button */}
{/* Accordion content - participants */} {isExpanded && participantCount > 0 && (
Участники ({participantCount})
{participants.map(participant => { const isAgent = participant.user_type === 'agent'; return (
{participant.avatar_url ? ( {participant.name} ) : (
{isAgent ? : }
)}
{participant.name}
{participant.role && participant.role !== 'member' && ( {participant.role === 'admin' ? 'Админ' : participant.role} )}
); })}
)}
); } export default AccordionChatItem;