import { useEffect, useState } from 'react' import { Box, Button, CircularProgress, Divider, Typography } from '@mui/material' import { ArrowRight, Building2, Calendar, MapPin, Ruler, Trophy } from 'lucide-react' import { useNavigate } from 'react-router' import { usePropertyById } from '../../hooks/useProperties' import { matchService } from '../../services/matchService' import type { AdditionalPropertyMatch } from '../../domain/additionalMatch' interface RelatedPropertyCardPanelProps { propertyId: string inquiryId: string } export function RelatedPropertyCardPanel({ propertyId, inquiryId }: RelatedPropertyCardPanelProps) { const { data: property, isLoading } = usePropertyById(propertyId) const navigate = useNavigate() const [additionalMatches, setAdditionalMatches] = useState([]) const [loadingMatches, setLoadingMatches] = useState(false) useEffect(() => { setLoadingMatches(true) matchService .getAdditionalMatchesForInquiry(inquiryId, { minScore: 80, excludePropertyId: propertyId }) .then(setAdditionalMatches) .finally(() => setLoadingMatches(false)) }, [inquiryId, propertyId]) if (isLoading) { return ( ) } if (!property) { return ( Objekt nicht gefunden ) } const image = property.images?.[0] return ( Bezogenes Objekt {!image && } {property.title} {property.location.city} {property.location.district ? `, ${property.location.district}` : ''} {property.areaSqm.toLocaleString('de-CH')} m² · CHF {property.rentPricePerSqm}/m²/Jahr Verfügbar ab {new Date(property.availabilityDate).toLocaleDateString('de-CH')} {property.description && ( {property.description} )} {/* Weitere Matches */} Weitere passende Objekte {loadingMatches ? ( ) : additionalMatches.length === 0 ? ( Keine weiteren Matches ) : ( {additionalMatches.map(m => ( ))} )} ) } function AdditionalMatchCard({ match }: { match: AdditionalPropertyMatch }) { const navigate = useNavigate() return ( {match.imageUrl && ( )} {match.title} = 90 ? '#fef3c7' : '#e0e7ff', color: match.matchScore >= 90 ? '#92400e' : '#3730a3', fontWeight: 700, fontSize: '0.65rem', flexShrink: 0, ml: 0.5, }} > {match.matchScore}% {match.location} · {match.areaSqm.toLocaleString('de-CH')} m² · CHF {match.rentPricePerSqm}/m²/Jahr {match.reasons.length > 0 && ( {match.reasons.map((r, i) => ( + {r} ))} )} {match.topUncertainty && ( ⚠ {match.topUncertainty} )} ) }