import { useMemo } from 'react' import { Box, CircularProgress, Typography } from '@mui/material' import { Target } from 'lucide-react' import { useProperties } from '../../hooks/useProperties' import { ResultType } from '../../domain/enums' import { useOfferWizardStore } from '../../stores/offerWizardStore' import { deterministicMatchScore } from './latentNeedUtils' import { SelectablePropertyMatchCard } from './SelectablePropertyMatchCard' import { OfferCreationPanel } from './OfferCreationPanel' import type { LatentNeed } from '../../domain/latentNeed' interface OwnPropertyMatchListProps { need: LatentNeed } function buildReason(propertyAssetType: string, needAssetType: string, city: string, location: string): string { if (propertyAssetType === needAssetType) { const cityMatch = location.toLowerCase().includes(city.toLowerCase()) || city.toLowerCase().includes(location.toLowerCase()) if (cityMatch) return 'Nutzungstyp und Standort passen sehr gut' return 'Passender Nutzungstyp, alternative Lage' } return 'Alternatives Profil — Detailprüfung empfohlen' } export function OwnPropertyMatchList({ need }: OwnPropertyMatchListProps) { const { data: properties = [], isLoading } = useProperties({ resultType: ResultType.VERIFIED_PORTFOLIO }) const selectedIds = useOfferWizardStore(s => s.selectedPropertyIds) const toggle = useOfferWizardStore(s => s.toggleProperty) const scored = useMemo(() => { return properties .map(p => ({ property: p, score: deterministicMatchScore(p.id, need.id), reason: buildReason(p.assetType, need.assetType, p.location.city, need.desiredLocation), })) .sort((a, b) => b.score - a.score) }, [properties, need]) return ( Eigene Objekte {scored.length} {isLoading && ( )} {!isLoading && scored.length === 0 && ( Keine Portfolio-Objekte vorhanden )} {scored.map(({ property, score, reason }) => ( toggle(property.id)} reason={reason} /> ))} ) }