import { useNavigate } from 'react-router' import { Box, Button, Card, Chip, IconButton, Tooltip, Typography } from '@mui/material' import { useDraggable } from '@dnd-kit/core' import { CSS } from '@dnd-kit/utilities' import { ExternalLink, MapPin, MessageSquare, Send, MessagesSquare } from 'lucide-react' import { MatchScoreDisplay } from '../match-card/MatchScoreDisplay' import { HeatBadge } from '../shared' import type { PipelineItem } from '../../domain/pipeline' import { STAGES, RESULT_TYPE_META } from './pipelineConstants' import { detailPath } from './pipelineUtils' import { useInquiryStore } from '../../stores/inquiryStore' // ── DraggableCard ───────────────────────────────────────────────────────────── export function DraggableCard({ item, isSelected, onSelect, isDragOverlay = false, onChatClick, }: { item: PipelineItem isSelected: boolean onSelect: (item: PipelineItem) => void isDragOverlay?: boolean onChatClick?: (e: React.MouseEvent) => void }) { const navigate = useNavigate() const openInquiryDialog = useInquiryStore(s => s.openInquiryDialog) const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ id: item.id }) const stageConfig = STAGES.find(s => s.key === item.stage) ?? STAGES[0] const path = detailPath(item) const style = !isDragOverlay ? { transform: CSS.Translate.toString(transform), opacity: isDragging ? 0.35 : 1, transition: isDragging ? undefined : 'opacity 0.15s ease', } : undefined return ( !isDragging && onSelect(item)} sx={{ p: 1.5, border: isSelected && !isDragOverlay ? '2px solid #1e3a5f' : isDragOverlay ? '2px solid transparent' : '2px solid transparent', cursor: isDragOverlay ? 'grabbing' : 'grab', bgcolor: isDragOverlay ? 'white' : isSelected ? '#eff6ff' : 'white', boxShadow: isDragOverlay ? '0 8px 24px rgba(0,0,0,0.18)' : '0 1px 3px rgba(0,0,0,0.08)', '&:hover': isDragOverlay ? {} : { boxShadow: '0 2px 8px rgba(0,0,0,0.12)', borderColor: isSelected ? '#152642' : '#bfdbfe', }, transition: isDragOverlay ? undefined : 'box-shadow 0.15s, border-color 0.15s', userSelect: 'none', rotate: isDragOverlay ? '2deg' : undefined, }} {...(isDragOverlay ? {} : { ...attributes, ...listeners })} > {/* Row 1: Score + type chip + chat icon */} {!isDragOverlay && ( {item.inquiryId && onChatClick && ( )} {path && ( { e.stopPropagation(); navigate(path) }} sx={{ p: 0.25, color: '#94a3b8', '&:hover': { color: '#152642', bgcolor: '#eff6ff' } }} > )} )} {/* Row 2: Title */} {item.title} {/* Row 3: Location */} {item.propertyAddress ?? item.location} {/* Row 4: Area + rent */} {(item.areaLabel || item.rentLabel) && ( {item.areaLabel && ( {item.areaLabel} )} {item.areaLabel && item.rentLabel && ( )} {item.rentLabel && ( {item.rentLabel} )} )} {/* Row 5: Notes preview */} {item.notes && ( {item.notes} )} {/* Row 6: Anfrage / Konversation */} {!isDragOverlay && ( {item.stage !== 'SAVED' || item.inquiryId ? ( ) : ( )} )} ) }