import { Box, Chip, Typography } from '@mui/material' import { Kanban } from 'lucide-react' import { INQUIRY_STATUS_META, DS_COLORS, DS_TEXT, DS_BG, DS_BORDER } from '../../lib/ds' import type { Inquiry } from '../../domain/inquiry' interface AnfragenInquiryItemProps { inq: Inquiry isSelected: boolean hasPipeline: boolean perspective?: 'demand' | 'supply' onSelect: (id: string) => void } export function AnfragenInquiryItem({ inq, isSelected, hasPipeline, perspective = 'supply', onSelect }: AnfragenInquiryItemProps) { const cfg = INQUIRY_STATUS_META[inq.status ?? 'new'] const displayDate = new Date(inq.updatedAt).toLocaleDateString('de-CH', { day: '2-digit', month: '2-digit' }) const lastMsg = inq.thread[inq.thread.length - 1] const unreadColor = cfg?.fg ?? DS_TEXT.danger const primaryTitle = perspective === 'demand' ? (inq.propertyAddress ?? inq.subject) : inq.tenantName const secondaryLine = perspective === 'demand' ? (inq.propertyManagerCompany ?? inq.propertyManagerName ?? '') : (inq.tenantCompany ?? '') const lastMsgPrefix = (() => { if (!lastMsg) return '' if (perspective === 'demand') { return lastMsg.senderType === 'tenant' ? 'Sie: ' : `${inq.propertyManagerName ?? 'Verwalter'}: ` } return lastMsg.senderType === 'tenant' ? 'Sie: ' : `${lastMsg.senderName}: ` })() return ( onSelect(inq.id)} sx={{ px: 2, py: 1.5, borderBottom: `1px solid ${DS_BORDER.muted}`, cursor: 'pointer', bgcolor: isSelected ? DS_COLORS.futureCard.signal.headerBg : !inq.isRead ? 'rgba(220,38,38,0.03)' : 'transparent', borderLeft: isSelected ? '3px solid' : '3px solid transparent', borderLeftColor: isSelected ? 'primary.main' : 'transparent', '&:hover': { bgcolor: isSelected ? DS_COLORS.futureCard.signal.headerBg : DS_BG.page }, transition: 'background-color 0.1s ease', }}> {!inq.isRead && } {primaryTitle} {inq.unreadCount > 0 && ( {inq.unreadCount} )} {displayDate} {secondaryLine && ( {secondaryLine} )} {inq.subject} {lastMsg && ( {lastMsgPrefix} {lastMsg.body.split('\n')[0]} )} {inq.matchScore && ( = 80 ? DS_TEXT.success : DS_TEXT.warning, fontWeight: 700, fontSize: '0.7rem' }}> {inq.matchScore}% )} {hasPipeline && ( } label="Pipeline" size="small" sx={{ height: 16, fontSize: '0.6rem', fontWeight: 600, bgcolor: DS_COLORS.futureCard.signal.headerBg, color: 'primary.main', '& .MuiChip-icon': { color: 'primary.main' }, }} /> )} ) }