Initial commit

This commit is contained in:
Benjamin Sutter
2026-05-15 00:48:18 +02:00
commit 9e827c50f9
72 changed files with 10477 additions and 0 deletions
+338
View File
@@ -0,0 +1,338 @@
import { useState } from 'react'
import {
Box,
Button,
Card,
Chip,
TextField,
Typography,
CircularProgress,
Alert,
Stack,
Divider,
} from '@mui/material'
import { Sparkles, ArrowRight } from 'lucide-react'
import { useNavigate } from 'react-router'
import { MockupAIServiceProvider, type CriteriaExtractionResult } from '../../services/aiService'
type Step = 'input' | 'extracting' | 'review' | 'done'
const EXAMPLE_QUERIES = [
'Büro Zürich 500-800m²',
'Logistik Basel 2000m²',
'Retail Bern Innenstadt',
]
function ConfidenceColor(score: number): string {
if (score >= 0.8) return '#1a7a4a'
if (score >= 0.6) return '#d97706'
return '#c0392b'
}
export default function AISearch() {
const navigate = useNavigate()
const [step, setStep] = useState<Step>('input')
const [inputText, setInputText] = useState('')
const [extractedCriteria, setExtractedCriteria] = useState<CriteriaExtractionResult | null>(null)
const [followUpAnswers, setFollowUpAnswers] = useState<Record<number, string>>({})
const handleAnalyze = async () => {
setStep('extracting')
await new Promise(r => setTimeout(r, 1500))
const result = await MockupAIServiceProvider.extractCriteria(inputText)
setExtractedCriteria(result)
setStep('review')
}
const handleStartSearch = () => {
navigate('/demand/results', { state: { needId: 'need-001' } })
}
return (
<Box>
{/* Page Header */}
<Box sx={{ bgcolor: 'white', borderBottom: '1px solid #e2e8f0', px: 3, py: 2 }}>
<Typography variant="h5" fontWeight={700} color="text.primary">
AI Bedarfsanalyse
</Typography>
<Typography variant="body2" color="text.secondary">
Beschreiben Sie Ihren Flächenbedarf in natürlicher Sprache
</Typography>
</Box>
<Box sx={{ px: 3, py: 3 }}>
{/* Step 1: Input */}
{step === 'input' && (
<Box>
<Card sx={{ maxWidth: 680, mx: 'auto', p: 3 }}>
<Typography variant="subtitle1" fontWeight={600} mb={2}>
Flächenbedarf beschreiben
</Typography>
<TextField
multiline
rows={5}
fullWidth
placeholder="Beispiel: Wir suchen 8001.000 m² Bürofläche in Zürich-West, verfügbar ab September 2025, Budget max. 45 CHF/m². Wichtig: gute ÖV-Anbindung, moderne Infrastruktur."
value={inputText}
onChange={e => setInputText(e.target.value)}
inputProps={{ maxLength: 2000 }}
sx={{ mb: 1 }}
/>
<Typography variant="caption" color="text.secondary" display="block" textAlign="right" mb={2}>
{inputText.length}/2000
</Typography>
<Button
variant="contained"
fullWidth
disabled={inputText.length < 20}
onClick={handleAnalyze}
endIcon={<Sparkles size={16} />}
sx={{ bgcolor: '#1e3a5f', '&:hover': { bgcolor: '#162d4a' }, mb: 2 }}
>
Analysieren
</Button>
<Typography variant="caption" color="text.secondary" display="block" textAlign="center">
Die KI extrahiert automatisch Kriterien, Standortpräferenzen und Budget aus Ihrer Beschreibung.
</Typography>
</Card>
{/* Example Queries */}
<Box sx={{ maxWidth: 680, mx: 'auto', mt: 2 }}>
<Typography variant="caption" color="text.secondary" display="block" mb={1}>
Beispiele:
</Typography>
<Stack direction="row" spacing={1} flexWrap="wrap" gap={1}>
{EXAMPLE_QUERIES.map(q => (
<Chip
key={q}
label={q}
size="small"
variant="outlined"
clickable
onClick={() => setInputText(q)}
sx={{ cursor: 'pointer' }}
/>
))}
</Stack>
</Box>
</Box>
)}
{/* Step 2: Extracting */}
{step === 'extracting' && (
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', py: 12, gap: 3 }}>
<CircularProgress size={48} sx={{ color: '#1e3a5f' }} />
<Typography variant="h6" color="text.secondary">
KI analysiert Ihren Bedarf...
</Typography>
</Box>
)}
{/* Step 3: Review */}
{step === 'review' && extractedCriteria && (
<Box>
<Box className="grid grid-cols-2 gap-4" sx={{ mb: 3 }}>
{/* Left: Extracted Criteria */}
<Card sx={{ p: 3 }}>
<Typography variant="subtitle1" fontWeight={600} mb={2}>
Extrahierte Kriterien
</Typography>
<Stack spacing={2}>
{/* Confidence badge */}
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 1 }}>
<Typography variant="caption" color="text.secondary">Gesamtkonfidenz:</Typography>
<Chip
label={`${Math.round(extractedCriteria.confidence * 100)}%`}
size="small"
sx={{
bgcolor: ConfidenceColor(extractedCriteria.confidence),
color: 'white',
fontWeight: 700,
}}
/>
</Box>
<Divider />
{/* Criteria items */}
{extractedCriteria.extractedCriteria.requiredArea && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(extractedCriteria.confidence) }}
>
Flächenbedarf
</Typography>
<Typography variant="body2">
{extractedCriteria.extractedCriteria.requiredArea.min}
{extractedCriteria.extractedCriteria.requiredArea.max} m²
</Typography>
</Box>
)}
{extractedCriteria.extractedCriteria.budgetRange && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(extractedCriteria.confidence) }}
>
Budget
</Typography>
<Typography variant="body2">
max. {extractedCriteria.extractedCriteria.budgetRange.maxPerSqm}{' '}
{extractedCriteria.extractedCriteria.budgetRange.currency}/m²
</Typography>
</Box>
)}
{extractedCriteria.extractedCriteria.companyName && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(0.5) }}
>
Unternehmen
</Typography>
<Typography variant="body2">
{extractedCriteria.extractedCriteria.companyName}
</Typography>
</Box>
)}
{extractedCriteria.extractedCriteria.preferredLocations && extractedCriteria.extractedCriteria.preferredLocations.length > 0 && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(0.85) }}
>
Standort
</Typography>
<Typography variant="body2">
{extractedCriteria.extractedCriteria.preferredLocations.join(', ')}
</Typography>
</Box>
)}
{extractedCriteria.extractedCriteria.timing && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(0.85) }}
>
Verfügbarkeit
</Typography>
<Typography variant="body2">
ab {extractedCriteria.extractedCriteria.timing.earliestMoveIn}
</Typography>
</Box>
)}
{extractedCriteria.extractedCriteria.assetType && (
<Box>
<Typography
variant="caption"
fontWeight={600}
sx={{ color: ConfidenceColor(0.85) }}
>
Objekttyp
</Typography>
<Typography variant="body2">
{extractedCriteria.extractedCriteria.assetType}
</Typography>
</Box>
)}
</Stack>
{/* Assumptions */}
{extractedCriteria.assumptions.length > 0 && (
<Box mt={3}>
<Typography variant="caption" fontWeight={600} color="text.secondary" display="block" mb={1}>
Annahmen der KI
</Typography>
<Stack spacing={0.5}>
{extractedCriteria.assumptions.map((a, i) => (
<Alert key={i} severity="warning" sx={{ py: 0, px: 1, '& .MuiAlert-message': { fontSize: 12 } }}>
{a}
</Alert>
))}
</Stack>
</Box>
)}
{/* Missing Fields */}
{extractedCriteria.missingFields.length > 0 && (
<Box mt={2}>
<Typography variant="caption" fontWeight={600} color="text.secondary" display="block" mb={1}>
Fehlende Informationen
</Typography>
<Stack direction="row" spacing={0.5} flexWrap="wrap" gap={0.5}>
{extractedCriteria.missingFields.map(f => (
<Chip
key={f}
label={f}
size="small"
color="warning"
variant="outlined"
/>
))}
</Stack>
</Box>
)}
</Card>
{/* Right: Follow-up Questions */}
<Card sx={{ p: 3 }}>
<Typography variant="subtitle1" fontWeight={600} mb={0.5}>
Rückfragen der KI
</Typography>
<Typography variant="caption" color="text.secondary" display="block" mb={2}>
Diese Fragen sind optional verbessern jedoch die Trefferqualität.
</Typography>
<Stack spacing={3}>
{extractedCriteria.followUpQuestions.map((q, i) => (
<Box key={i}>
<Typography variant="body2" fontWeight={500} mb={1}>
{i + 1}. {q}
</Typography>
<TextField
size="small"
fullWidth
placeholder="Ihre Antwort (optional)"
value={followUpAnswers[i] ?? ''}
onChange={e =>
setFollowUpAnswers(prev => ({ ...prev, [i]: e.target.value }))
}
/>
</Box>
))}
</Stack>
</Card>
</Box>
{/* Footer Actions */}
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 2 }}>
<Button variant="outlined" onClick={() => setStep('input')}>
Zurück
</Button>
<Button
variant="contained"
onClick={handleStartSearch}
endIcon={<ArrowRight size={16} />}
sx={{ bgcolor: '#1e3a5f', '&:hover': { bgcolor: '#162d4a' } }}
>
Suche starten
</Button>
</Box>
</Box>
)}
</Box>
</Box>
)
}
+320
View File
@@ -0,0 +1,320 @@
import {
Box,
Button,
Card,
Chip,
Typography,
LinearProgress,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
CircularProgress,
Stack,
} from '@mui/material'
import { X } from 'lucide-react'
import { useQuery } from '@tanstack/react-query'
import { useNavigate } from 'react-router'
import { propertyService } from '../../services/propertyService'
import { useCompareStore } from '../../stores/compareStore'
import { EmptyState } from '../../components/ui'
import { ResultType, RiskLevel } from '../../domain/enums'
import type { Property } from '../../domain/property'
function getResultTypeLabel(type: ResultType): string {
switch (type) {
case ResultType.VERIFIED_PORTFOLIO: return 'Verified Portfolio'
case ResultType.EXTERNAL_MARKET: return 'Marktinserat'
case ResultType.FUTURE_AVAILABILITY: return 'Zukunftssignal'
}
}
function getResultTypeColor(type: ResultType): string {
switch (type) {
case ResultType.VERIFIED_PORTFOLIO: return '#1e3a5f'
case ResultType.EXTERNAL_MARKET: return '#d97706'
case ResultType.FUTURE_AVAILABILITY: return '#7c3aed'
}
}
function getRiskColor(risk?: RiskLevel): 'success' | 'warning' | 'error' | 'default' {
if (!risk) return 'default'
if (risk === RiskLevel.LOW) return 'success'
if (risk === RiskLevel.MEDIUM) return 'warning'
return 'error'
}
function getRiskLabel(risk?: RiskLevel): string {
if (!risk) return ''
switch (risk) {
case RiskLevel.LOW: return 'Niedrig'
case RiskLevel.MEDIUM: return 'Mittel'
case RiskLevel.HIGH: return 'Hoch'
case RiskLevel.CRITICAL: return 'Kritisch'
}
}
interface CompareRow {
label: string
getValue: (p: Property) => string | number | null
format?: (v: string | number | null, p: Property) => React.ReactNode
isHigherBetter?: boolean
isLowerBetter?: boolean
}
function NumericCell({ value, isBest }: { value: React.ReactNode; isBest: boolean }) {
return (
<TableCell
sx={{
bgcolor: isBest ? '#f0fdf4' : 'transparent',
fontWeight: isBest ? 700 : 400,
color: isBest ? '#1a7a4a' : 'inherit',
borderLeft: '1px solid #f1f5f9',
}}
>
{value}
</TableCell>
)
}
export default function Compare() {
const navigate = useNavigate()
const { compareTray, removeFromCompare, clearCompare } = useCompareStore()
const { data: propResp, isLoading } = useQuery({
queryKey: ['properties'],
queryFn: () => propertyService.getAll(),
})
const properties = propResp?.data ?? []
const compareProperties = properties.filter(p => compareTray.includes(p.id))
// Keep ordering same as tray
const orderedProperties = compareTray
.map(id => compareProperties.find(p => p.id === id))
.filter((p): p is Property => p !== null)
if (isLoading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', py: 12 }}>
<CircularProgress />
</Box>
)
}
if (compareTray.length === 0) {
return (
<Box>
<Box sx={{ bgcolor: 'white', borderBottom: '1px solid #e2e8f0', px: 3, py: 2 }}>
<Typography variant="h5" fontWeight={700}>Vergleich</Typography>
</Box>
<Box sx={{ px: 3, py: 3 }}>
<EmptyState
title="Keine Objekte zum Vergleich"
description="Fügen Sie Objekte aus den Suchergebnissen zum Vergleich hinzu."
action={{ label: 'Zur Suche', onClick: () => navigate('/demand/results') }}
/>
</Box>
</Box>
)
}
const rows: CompareRow[] = [
{
label: 'Fläche (m²)',
getValue: p => p.areaSqm,
isHigherBetter: false,
},
{
label: 'Miete/m² (CHF)',
getValue: p => p.rentPricePerSqm,
isLowerBetter: true,
},
{
label: 'Gesamtmiete/Monat (CHF)',
getValue: p => p.totalRentMonthly ?? null,
format: (v) => v != null ? `${Number(v).toLocaleString('de-CH')} CHF` : <em style={{ color: '#94a3b8' }}></em>,
isLowerBetter: true,
},
{
label: 'Verfügbarkeit',
getValue: p => p.availabilityDate,
format: (v) => v ?? <em style={{ color: '#94a3b8' }}></em>,
},
{
label: 'Standort',
getValue: p => `${p.location.city}${p.location.district ? ', ' + p.location.district : ''}`,
},
{
label: 'Datenqualität',
getValue: p => p.dataQuality.score,
format: (v, p) => (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Box sx={{ width: 80 }}>
<LinearProgress
variant="determinate"
value={p.dataQuality.score * 100}
sx={{ height: 6, borderRadius: 3 }}
color={p.dataQuality.score >= 0.8 ? 'success' : p.dataQuality.score >= 0.6 ? 'warning' : 'error'}
/>
</Box>
<Typography variant="caption">{Math.round(p.dataQuality.score * 100)}%</Typography>
</Box>
),
isHigherBetter: true,
},
{
label: 'Konfidenz',
getValue: p => p.confidenceScore,
format: (v) => v != null ? `${Math.round(Number(v) * 100)}%` : <em style={{ color: '#94a3b8' }}></em>,
isHigherBetter: true,
},
{
label: 'Risiko',
getValue: p => p.riskLevel ?? null,
format: (v, p) => (
<Chip
label={getRiskLabel(p.riskLevel)}
size="small"
color={getRiskColor(p.riskLevel)}
variant="outlined"
/>
),
},
{
label: 'Prestige',
getValue: p => p.softFactors?.prestige ?? null,
format: (v) => v != null ? String(v) : <em style={{ color: '#94a3b8' }}></em>,
isHigherBetter: true,
},
{
label: 'Erreichbarkeit',
getValue: p => p.softFactors?.accessibility ?? null,
format: (v) => v != null ? String(v) : <em style={{ color: '#94a3b8' }}></em>,
isHigherBetter: true,
},
{
label: 'ÖV-Minuten',
getValue: p => p.softFactors?.publicTransportMinutes ?? null,
format: (v) => v != null ? `${v} Min.` : <em style={{ color: '#94a3b8' }}></em>,
isLowerBetter: true,
},
{
label: 'Fehlende Pflichtfelder',
getValue: p => p.dataQuality.missingCriticalFields.length,
format: (v) => v != null ? String(v) : <em style={{ color: '#94a3b8' }}></em>,
isLowerBetter: true,
},
]
return (
<Box>
{/* Page Header */}
<Box sx={{ bgcolor: 'white', borderBottom: '1px solid #e2e8f0', px: 3, py: 2, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Typography variant="h5" fontWeight={700}>Vergleich</Typography>
<Chip label={`${orderedProperties.length} Objekte`} size="small" />
</Box>
<Button variant="outlined" size="small" color="error" onClick={clearCompare}>
Leeren
</Button>
</Box>
<Box sx={{ px: 3, py: 3 }}>
<Card sx={{ overflowX: 'auto' }}>
<Table>
<TableHead>
<TableRow sx={{ bgcolor: '#f8fafc' }}>
<TableCell sx={{ width: 180, fontWeight: 600, color: '#64748b', fontSize: 12 }}>
Kriterium
</TableCell>
{orderedProperties.map(p => (
<TableCell key={p.id} sx={{ borderLeft: '1px solid #f1f5f9', minWidth: 220 }}>
<Box sx={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 1 }}>
<Box>
<Typography variant="body2" fontWeight={600}>{p.title}</Typography>
<Chip
label={getResultTypeLabel(p.resultType)}
size="small"
sx={{
bgcolor: getResultTypeColor(p.resultType),
color: 'white',
fontSize: 10,
mt: 0.5,
}}
/>
</Box>
<Button
size="small"
sx={{ minWidth: 'auto', p: 0.5 }}
onClick={() => removeFromCompare(p.id)}
>
<X size={14} />
</Button>
</Box>
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map(row => {
const values = orderedProperties.map(p => row.getValue(p))
const numericValues = values
.map((v, i) => ({ v, i }))
.filter(x => x.v != null && typeof x.v === 'number') as { v: number; i: number }[]
let bestIdx = -1
if (numericValues.length > 1) {
if (row.isHigherBetter) {
bestIdx = numericValues.reduce((best, cur) => cur.v > best.v ? cur : best).i
} else if (row.isLowerBetter) {
bestIdx = numericValues.reduce((best, cur) => cur.v < best.v ? cur : best).i
}
}
return (
<TableRow key={row.label} hover>
<TableCell sx={{ color: '#64748b', fontSize: 13, fontWeight: 500 }}>
{row.label}
</TableCell>
{orderedProperties.map((p, idx) => {
const raw = row.getValue(p)
const displayValue = row.format
? row.format(raw, p)
: raw != null
? String(raw)
: <em style={{ color: '#94a3b8' }}></em>
const isBest = bestIdx === idx
return (
<NumericCell key={p.id} value={displayValue} isBest={isBest} />
)
})}
</TableRow>
)
})}
</TableBody>
</Table>
</Card>
{/* Add more prompt */}
{orderedProperties.length < 3 && (
<Card sx={{ p: 2.5, mt: 2, border: '2px dashed #e2e8f0', boxShadow: 'none' }}>
<Stack direction="row" alignItems="center" justifyContent="space-between">
<Box>
<Typography variant="subtitle2" fontWeight={600}>Weiteres Objekt hinzufügen</Typography>
<Typography variant="caption" color="text.secondary">
Bis zu {3 - orderedProperties.length} weitere{orderedProperties.length < 2 ? 's' : ''} Objekt{orderedProperties.length < 2 ? '' : 'e'} möglich
</Typography>
</Box>
<Button variant="outlined" size="small" onClick={() => navigate('/demand/results')}>
Zur Suche
</Button>
</Stack>
</Card>
)}
</Box>
</Box>
)
}
+476
View File
@@ -0,0 +1,476 @@
import { useState } from 'react'
import {
Box,
Button,
Card,
Chip,
Typography,
LinearProgress,
Stack,
Alert,
CircularProgress,
Divider,
} from '@mui/material'
import {
MapPin,
Maximize2,
Banknote,
Calendar,
Bookmark,
Columns2,
} from 'lucide-react'
import { useQuery } from '@tanstack/react-query'
import { useNavigate, useLocation } from 'react-router'
import { propertyService } from '../../services/propertyService'
import { matchService } from '../../services/matchService'
import { needService } from '../../services/needService'
import { ResultType, MatchStrength, RiskLevel } from '../../domain/enums'
import type { Property } from '../../domain/property'
import type { Match } from '../../domain/match'
import { useCompareStore } from '../../stores/compareStore'
import { EmptyState } from '../../components/ui'
type FilterSource = ResultType | 'ALL'
type SortBy = 'score' | 'rent' | 'area'
function getResultTypeLabel(type: ResultType): string {
switch (type) {
case ResultType.VERIFIED_PORTFOLIO: return 'Verified Portfolio'
case ResultType.EXTERNAL_MARKET: return 'Marktinserat'
case ResultType.FUTURE_AVAILABILITY: return 'Zukunftssignal'
}
}
function getResultTypeColor(type: ResultType): string {
switch (type) {
case ResultType.VERIFIED_PORTFOLIO: return '#1e3a5f'
case ResultType.EXTERNAL_MARKET: return '#d97706'
case ResultType.FUTURE_AVAILABILITY: return '#7c3aed'
}
}
function getMatchStrengthColor(strength: MatchStrength): string {
switch (strength) {
case MatchStrength.STRONG: return '#1a7a4a'
case MatchStrength.MODERATE: return '#d97706'
case MatchStrength.WEAK: return '#c0392b'
}
}
function getRiskChipColor(risk: RiskLevel): 'success' | 'warning' | 'error' {
if (risk === RiskLevel.LOW) return 'success'
if (risk === RiskLevel.MEDIUM) return 'warning'
return 'error'
}
function getRiskLabel(risk: RiskLevel): string {
switch (risk) {
case RiskLevel.LOW: return 'Niedriges Risiko'
case RiskLevel.MEDIUM: return 'Mittleres Risiko'
case RiskLevel.HIGH: return 'Hohes Risiko'
case RiskLevel.CRITICAL: return 'Kritisches Risiko'
}
}
interface ResultCardProps {
property: Property
match: Match
onCompare: (id: string) => void
isInCompare: boolean
}
function ResultCard({ property, match, onCompare, isInCompare }: ResultCardProps) {
const scoreColor = getMatchStrengthColor(match.matchStrength)
return (
<Card sx={{ p: 2.5, mb: 1.5 }}>
{/* Future signal warning */}
{property.resultType === ResultType.FUTURE_AVAILABILITY && (
<Alert severity="warning" sx={{ mb: 1.5, py: 0.5 }}>
Probabilistisches Signal kein bestätigtes Objekt
</Alert>
)}
{/* Header row */}
<Box sx={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', mb: 1.5 }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
<Chip
label={getResultTypeLabel(property.resultType)}
size="small"
sx={{
bgcolor: getResultTypeColor(property.resultType),
color: 'white',
fontWeight: 600,
fontSize: 11,
}}
/>
<Typography variant="h6" fontWeight={600}>
{property.title}
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'baseline', gap: 0.5 }}>
<Typography variant="h4" fontWeight={800} sx={{ color: scoreColor }}>
{match.matchScore}
</Typography>
<Typography variant="body2" color="text.secondary">/100</Typography>
</Box>
</Box>
{/* Property details row */}
<Stack direction="row" spacing={2.5} sx={{ mb: 1.5 }} flexWrap="wrap">
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<MapPin size={14} color="#64748b" />
<Typography variant="body2" color="text.secondary">
{property.location.city}
{property.location.district ? `, ${property.location.district}` : ''}
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<Maximize2 size={14} color="#64748b" />
<Typography variant="body2" color="text.secondary">
{property.areaSqm} m²
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<Banknote size={14} color="#64748b" />
<Typography variant="body2" color="text.secondary">
CHF {property.rentPricePerSqm}/m²
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<Calendar size={14} color="#64748b" />
<Typography variant="body2" color="text.secondary">
{property.availabilityDate}
</Typography>
</Box>
</Stack>
{/* Match factors section */}
<Divider sx={{ mb: 1.5 }} />
{match.positiveFactors.length > 0 && (
<Box sx={{ mb: 1 }}>
<Typography variant="caption" fontWeight={600} color="text.secondary" display="block" mb={0.5}>
Positive Faktoren
</Typography>
<Stack direction="row" spacing={0.5} flexWrap="wrap" gap={0.5}>
{match.positiveFactors.slice(0, 3).map((f, i) => (
<Chip
key={i}
label={f.criterion}
size="small"
sx={{ bgcolor: '#f0fdf4', color: '#1a7a4a', border: '1px solid #bbf7d0', fontSize: 11 }}
/>
))}
</Stack>
</Box>
)}
{match.tradeoffs.length > 0 && (
<Alert severity="warning" sx={{ py: 0.5, px: 1.5, mb: 1, '& .MuiAlert-message': { fontSize: 12 } }}>
<Typography variant="caption" fontWeight={600} display="block" mb={0.5}>Abwägungen</Typography>
{match.tradeoffs.slice(0, 2).map((t, i) => (
<Typography key={i} variant="caption" display="block">
{t.criterion}: {t.concern}
</Typography>
))}
</Alert>
)}
{/* Confidence + Quality row */}
<Stack direction="row" spacing={2.5} alignItems="center" sx={{ mb: 1.5 }} flexWrap="wrap">
<Typography variant="caption">
<span style={{ color: '#64748b' }}>Konfidenz </span>
<strong style={{ color: match.confidenceLevel >= 0.8 ? '#1a7a4a' : match.confidenceLevel >= 0.6 ? '#d97706' : '#c0392b' }}>
{Math.round(match.confidenceLevel * 100)}%
</strong>
</Typography>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Typography variant="caption" color="text.secondary">Datenqualität</Typography>
<Box sx={{ width: 80 }}>
<LinearProgress
variant="determinate"
value={property.dataQuality.score * 100}
sx={{ height: 6, borderRadius: 3 }}
color={
property.dataQuality.score >= 0.8 ? 'success' :
property.dataQuality.score >= 0.6 ? 'warning' : 'error'
}
/>
</Box>
<Typography variant="caption" color="text.secondary">
{Math.round(property.dataQuality.score * 100)}%
</Typography>
</Box>
{property.riskLevel && (
<Chip
label={getRiskLabel(property.riskLevel)}
size="small"
color={getRiskChipColor(property.riskLevel)}
variant="outlined"
/>
)}
</Stack>
{/* Actions row */}
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button
variant="outlined"
size="small"
startIcon={<Bookmark size={14} />}
disabled
>
Shortlist
</Button>
<Button
variant={isInCompare ? 'contained' : 'outlined'}
size="small"
startIcon={<Columns2 size={14} />}
onClick={() => onCompare(property.id)}
sx={isInCompare ? { bgcolor: '#1e3a5f' } : {}}
>
Vergleichen
</Button>
<Button
variant="contained"
size="small"
disabled
sx={{ bgcolor: '#1e3a5f', '&:hover': { bgcolor: '#162d4a' } }}
>
Details
</Button>
</Box>
</Card>
)
}
export default function Results() {
const navigate = useNavigate()
const location = useLocation()
const _needId = (location.state as { needId?: string } | null)?.needId ?? 'need-001'
const [filterSource, setFilterSource] = useState<FilterSource>('ALL')
const [sortBy, setSortBy] = useState<SortBy>('score')
const { data: propResp, isLoading: propLoading } = useQuery({
queryKey: ['properties'],
queryFn: () => propertyService.getAll(),
})
const { data: matchResp, isLoading: matchLoading } = useQuery({
queryKey: ['matches'],
queryFn: () => matchService.getAll(),
})
const { data: needResp, isLoading: needLoading } = useQuery({
queryKey: ['needs'],
queryFn: () => needService.getAll(),
})
const { addToCompare, removeFromCompare, clearCompare, isInCompare, compareTray } = useCompareStore()
const properties = propResp?.data ?? []
const matches = matchResp?.data ?? []
const needs = needResp?.data ?? []
const activeNeed = needs[0]
const isLoading = propLoading || matchLoading || needLoading
// Join matches with properties
const resultItems = matches
.map(match => {
const property = properties.find(p => p.id === match.propertyId)
return property ? { match, property } : null
})
.filter((item): item is { match: Match; property: Property } => item !== null)
// Filter by source
const filtered = filterSource === 'ALL'
? resultItems
: resultItems.filter(item => item.property.resultType === filterSource)
// Sort
const sorted = [...filtered].sort((a, b) => {
if (sortBy === 'score') return b.match.matchScore - a.match.matchScore
if (sortBy === 'rent') return a.property.rentPricePerSqm - b.property.rentPricePerSqm
if (sortBy === 'area') return b.property.areaSqm - a.property.areaSqm
return 0
})
const verifiedCount = resultItems.filter(i => i.property.resultType === ResultType.VERIFIED_PORTFOLIO).length
const externalCount = resultItems.filter(i => i.property.resultType === ResultType.EXTERNAL_MARKET).length
const futureCount = resultItems.filter(i => i.property.resultType === ResultType.FUTURE_AVAILABILITY).length
const handleToggleCompare = (id: string) => {
if (isInCompare(id)) {
removeFromCompare(id)
} else {
addToCompare(id)
}
}
if (isLoading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', py: 12 }}>
<CircularProgress />
</Box>
)
}
return (
<Box>
{/* Page Header */}
<Box sx={{ bgcolor: 'white', borderBottom: '1px solid #e2e8f0', px: 3, py: 2, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<Box>
<Typography variant="h5" fontWeight={700} color="text.primary">
{sorted.length} Treffer gefunden
</Typography>
<Typography variant="body2" color="text.secondary">
{verifiedCount} Verified · {externalCount} Extern · {futureCount} Signale
</Typography>
</Box>
</Box>
<Box sx={{ px: 3, py: 3 }}>
{/* Active Need Banner */}
{activeNeed && (
<Card sx={{ bgcolor: '#eff6ff', p: 2, mb: 2, border: '1px solid #bfdbfe' }}>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<Box>
<Typography variant="subtitle2" fontWeight={600} color="#1e3a5f">
Aktive Suche: {activeNeed.companyName}
</Typography>
<Typography variant="caption" color="text.secondary">
{activeNeed.assetType} · {activeNeed.requiredArea.min}{activeNeed.requiredArea.max} m² ·{' '}
{activeNeed.preferredLocations.join(', ')}
</Typography>
</Box>
<Button
size="small"
variant="text"
onClick={() => navigate('/demand/ai-search')}
sx={{ color: '#1e3a5f' }}
>
Suche ändern
</Button>
</Box>
</Card>
)}
{/* Filter/Sort bar */}
<Card sx={{ p: 1.5, mb: 2 }}>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 1 }}>
<Stack direction="row" spacing={0.5} flexWrap="wrap" gap={0.5}>
{(['ALL', ResultType.VERIFIED_PORTFOLIO, ResultType.EXTERNAL_MARKET, ResultType.FUTURE_AVAILABILITY] as FilterSource[]).map(source => {
const labels: Record<FilterSource, string> = {
ALL: 'Alle',
[ResultType.VERIFIED_PORTFOLIO]: 'Verified Portfolio',
[ResultType.EXTERNAL_MARKET]: 'Marktinserate',
[ResultType.FUTURE_AVAILABILITY]: 'Zukunftssignale',
}
const colors: Partial<Record<FilterSource, string>> = {
[ResultType.VERIFIED_PORTFOLIO]: '#1e3a5f',
[ResultType.EXTERNAL_MARKET]: '#d97706',
[ResultType.FUTURE_AVAILABILITY]: '#7c3aed',
}
const isActive = filterSource === source
return (
<Chip
key={source}
label={labels[source]}
size="small"
clickable
onClick={() => setFilterSource(source)}
sx={{
bgcolor: isActive ? (colors[source] ?? '#1e3a5f') : 'transparent',
color: isActive ? 'white' : 'text.secondary',
border: `1px solid ${isActive ? (colors[source] ?? '#1e3a5f') : '#e2e8f0'}`,
fontWeight: isActive ? 600 : 400,
}}
/>
)
})}
</Stack>
<Stack direction="row" spacing={0.5} alignItems="center">
<Typography variant="caption" color="text.secondary">Sortierung:</Typography>
{([['score', 'Relevanz'], ['area', 'Fläche'], ['rent', 'Mietpreis']] as [SortBy, string][]).map(([val, label]) => (
<Chip
key={val}
label={label}
size="small"
clickable
onClick={() => setSortBy(val)}
sx={{
bgcolor: sortBy === val ? '#1e3a5f' : 'transparent',
color: sortBy === val ? 'white' : 'text.secondary',
border: `1px solid ${sortBy === val ? '#1e3a5f' : '#e2e8f0'}`,
}}
/>
))}
</Stack>
</Box>
</Card>
{/* Results */}
{sorted.length === 0 ? (
<EmptyState
title="Keine Treffer gefunden"
description="Passen Sie die Suchkriterien an oder wechseln Sie den Filter."
/>
) : (
sorted.map(({ match, property }) => (
<ResultCard
key={match.id}
property={property}
match={match}
onCompare={handleToggleCompare}
isInCompare={isInCompare(property.id)}
/>
))
)}
</Box>
{/* Compare Tray */}
{compareTray.length > 0 && (
<Box
sx={{
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
bgcolor: '#1e3a5f',
color: 'white',
py: 1.5,
px: 3,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
zIndex: 1200,
boxShadow: '0 -4px 12px rgba(0,0,0,0.15)',
}}
>
<Typography variant="body2" fontWeight={600}>
{compareTray.length} Objekte zum Vergleich ausgewählt
</Typography>
<Stack direction="row" spacing={1}>
<Button
size="small"
variant="outlined"
sx={{ color: 'white', borderColor: 'rgba(255,255,255,0.5)' }}
onClick={clearCompare}
>
Leeren
</Button>
<Button
size="small"
variant="contained"
sx={{ bgcolor: 'white', color: '#1e3a5f', '&:hover': { bgcolor: '#f1f5f9' } }}
onClick={() => navigate('/demand/compare')}
>
Vergleich starten
</Button>
</Stack>
</Box>
)}
</Box>
)
}
+174
View File
@@ -0,0 +1,174 @@
import {
Box,
Button,
Card,
Chip,
Typography,
Stack,
Divider,
List,
ListItem,
ListItemText,
} from '@mui/material'
import { Bookmark } from 'lucide-react'
interface MockShortlist {
id: string
title: string
company: string
assetType: string
objectCount: number
createdAt: string
updatedAt: string
properties: string[]
}
const MOCK_SHORTLISTS: MockShortlist[] = [
{
id: 'sl-001',
title: 'Bürosuche Innovatech AG',
company: 'Innovatech AG',
assetType: 'Büro',
objectCount: 2,
createdAt: '01.05.2025',
updatedAt: '08.05.2025',
properties: ['Bürofläche Zollstrasse 12', 'Gemischte Gewerbeeinheit Europaallee'],
},
{
id: 'sl-002',
title: 'Logistik Basel — Schweizer Logistik',
company: 'Schweizer Logistik GmbH',
assetType: 'Logistik',
objectCount: 1,
createdAt: '03.05.2025',
updatedAt: '03.05.2025',
properties: ['Lagerfläche Hardstrasse 44'],
},
]
export default function Shortlists() {
return (
<Box>
{/* Page Header */}
<Box
sx={{
bgcolor: 'white',
borderBottom: '1px solid #e2e8f0',
px: 3,
py: 2,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<Box>
<Typography variant="h5" fontWeight={700} color="text.primary">
Shortlists
</Typography>
<Typography variant="body2" color="text.secondary">
Gespeicherte Objektlisten und Entscheidungsvorlagen
</Typography>
</Box>
<Button
variant="contained"
size="small"
startIcon={<Bookmark size={14} />}
disabled
sx={{ bgcolor: '#1e3a5f' }}
>
Neue Shortlist
</Button>
</Box>
<Box sx={{ px: 3, py: 3 }}>
<Stack spacing={2}>
{MOCK_SHORTLISTS.map(sl => (
<Card key={sl.id} sx={{ p: 2.5 }}>
{/* Card header */}
<Box
sx={{
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'space-between',
mb: 1.5,
}}
>
<Box>
<Typography variant="subtitle1" fontWeight={700}>
{sl.title}
</Typography>
<Typography variant="body2" color="text.secondary">
{sl.company} · {sl.assetType}
</Typography>
</Box>
<Chip
label={`${sl.objectCount} Objekte`}
size="small"
sx={{ bgcolor: '#eff6ff', color: '#1e3a5f', fontWeight: 600 }}
/>
</Box>
{/* Dates */}
<Stack direction="row" spacing={2} sx={{ mb: 1.5 }}>
<Typography variant="caption" color="text.secondary">
Erstellt: {sl.createdAt}
</Typography>
<Typography variant="caption" color="text.secondary">
Zuletzt aktualisiert: {sl.updatedAt}
</Typography>
</Stack>
<Divider sx={{ mb: 1.5 }} />
{/* Property list */}
<List dense disablePadding sx={{ mb: 1.5 }}>
{sl.properties.map((prop, i) => (
<ListItem key={i} disableGutters sx={{ py: 0.25 }}>
<Box
sx={{
width: 6,
height: 6,
borderRadius: '50%',
bgcolor: '#1e3a5f',
mr: 1.5,
flexShrink: 0,
}}
/>
<ListItemText
primary={prop}
primaryTypographyProps={{ variant: 'body2' }}
/>
</ListItem>
))}
</List>
{/* Actions */}
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button variant="outlined" size="small" disabled>
Teilen
</Button>
<Button variant="outlined" size="small" disabled>
Öffnen
</Button>
</Box>
</Card>
))}
{/* Empty shortlist prompt */}
<Card
sx={{
p: 2,
border: '2px dashed #e2e8f0',
boxShadow: 'none',
bgcolor: '#fafafa',
}}
>
<Typography variant="body2" color="text.secondary" textAlign="center">
Objekte aus den Suchergebnissen zur Shortlist hinzufügen
</Typography>
</Card>
</Stack>
</Box>
</Box>
)
}