import { Box, Button, Chip, IconButton, Tooltip, Typography } from '@mui/material' import { X, AlertTriangle, BookmarkCheck, ExternalLink, Kanban } from 'lucide-react' import { useNavigate } from 'react-router' import { usePipelineItems } from '../../hooks/usePipeline' import { usePipelineStore } from '../../stores/pipelineStore' import { RESULT_TYPE_META } from '../../lib/ds' import { matchScoreHex } from '../../lib/utils' import type { UnifiedMatchResult } from '../../domain/unifiedResult' interface Props { item: UnifiedMatchResult onRemove: () => void } export function CompareColumnHeader({ item, onRemove }: Props) { const navigate = useNavigate() const { data: pipelineItems = [] } = usePipelineItems() const { openSavedDialog } = usePipelineStore() const meta = RESULT_TYPE_META[item.resultType] ?? { label: item.resultType, color: '#64748b' } const prop = item.resultType !== 'FUTURE_AVAILABILITY' ? (item as any).property : null const sig = item.resultType === 'FUTURE_AVAILABILITY' ? (item as any).signal : null const title = prop?.title ?? sig?.companyName ?? sig?.locationHint ?? '–' const subtitle = prop?.location?.city ?? sig?.locationHint ?? '–' const district = prop?.location?.district const availability = prop?.availabilityDate ?? (sig ? `~${sig.timeHorizonMonths} Monate` : null) const confidence = Math.round(item.match.confidenceLevel * 100) const source = prop?.sourceLabel ?? sig?.source?.type ?? '–' const isInPipeline = pipelineItems.some( pi => pi.id === item.matchId || (prop?.id && pi.propertyId === prop.id) ) function handleSave() { if (isInPipeline) return openSavedDialog({ resultId: item.matchId, resultType: item.resultType, title, location: prop?.location?.city ?? sig?.locationHint, matchScore: item.matchScore, propertyId: prop?.id, propertyAddress: prop ? `${title}, ${subtitle}${district ? `, ${district}` : ''}` : undefined, areaLabel: prop?.areaSqm ? `${prop.areaSqm.toLocaleString('de-CH')} m²` : undefined, rentLabel: prop?.rentPricePerSqm ? `CHF ${prop.rentPricePerSqm}/m²/Jahr` : undefined, availabilityLabel: prop?.availabilityDate ?? undefined, }) } return ( {/* Row 1: type chip + remove */} {/* Row 2: title (clickable) */} navigate(`/demand/results/${item.matchId}`)} > {title} {subtitle}{district ? `, ${district}` : ''} {/* Row 3: score */} {item.matchScore} /100 {/* Row 4: meta chips */} : undefined} sx={{ fontSize: 10, bgcolor: confidence < 60 ? '#fef3c7' : '#f0fdf4', color: confidence < 60 ? '#92400e' : '#166534', }} /> {source && source !== '–' && ( )} {availability && ( )} {item.resultType === 'FUTURE_AVAILABILITY' && sig && ( Probabilistisches Signal {Math.round(sig.probability * 100)}% Wahrscheinlichkeit )} {/* Row 5: action buttons */} {isInPipeline ? ( ) : ( )} ) }