import { useMemo, useState } from 'react' import { Box, Chip, Drawer, IconButton, MenuItem, Select, Typography, } from '@mui/material' import { X } from 'lucide-react' import { useMatches, useApproveMatch } from '../../hooks/useMatches' import { useProperties } from '../../hooks/useProperties' import { useNeeds } from '../../hooks/useNeeds' import { useMatchCenterStore } from '../../stores/matchCenterStore' import { useToastStore } from '../../stores/toastStore' import { MatchListCard, MatchBriefingPanel, MatchCenterSkeleton } from '../../components/match-center' import { ErrorState } from '../../components/ui' import type { Match } from '../../domain/match' const STRENGTH_OPTIONS = [ { value: '', label: 'Alle Stärken' }, { value: 'STRONG', label: 'Stark (≥80)' }, { value: 'MODERATE', label: 'Mittel (60–79)' }, { value: 'WEAK', label: 'Schwach (<60)' }, ] const STATUS_OPTIONS = [ { value: '', label: 'Alle Status' }, { value: 'PENDING_REVIEW', label: 'Ausstehend' }, { value: 'APPROVED', label: 'Genehmigt' }, { value: 'REJECTED', label: 'Abgelehnt' }, ] export default function MatchCenter() { const { data: matches = [], isLoading, isError, refetch } = useMatches() const { data: properties = [] } = useProperties() const { data: needs = [] } = useNeeds() const { setSelectedProperty, setSelectedNeed } = useMatchCenterStore() const approveMatch = useApproveMatch() const showToast = useToastStore((s) => s.showToast) const [selectedMatchId, setSelectedMatchId] = useState(null) const [filterStrength, setFilterStrength] = useState('') const [filterStatus, setFilterStatus] = useState('') const propMap = useMemo(() => new Map(properties.map(p => [p.id, p])), [properties]) const needMap = useMemo(() => new Map(needs.map(n => [n.id, n])), [needs]) const filtered = useMemo(() => { return matches .filter(m => { if (filterStrength && m.matchStrength !== filterStrength) return false if (filterStatus && m.status !== filterStatus) return false return true }) .sort((a, b) => b.matchScore - a.matchScore) }, [matches, filterStrength, filterStatus]) const strongCount = matches.filter(m => m.matchScore >= 80).length const pendingCount = matches.filter(m => m.status === 'PENDING_REVIEW').length function handleSelectMatch(match: Match) { setSelectedMatchId(match.id) setSelectedProperty(match.propertyId) setSelectedNeed(match.needId) } function handleCloseDrawer() { setSelectedMatchId(null) setSelectedProperty(null) setSelectedNeed(null) } return ( {/* Header */} Match Center Automatisch berechnete Matches {pendingCount > 0 && ( )} {/* Filter bar */} {filtered.length} von {matches.length} Matches {/* Match list */} {isLoading ? ( ) : isError ? ( ) : filtered.length === 0 ? ( Keine Matches für diese Filter. ) : ( {filtered.map(match => ( handleSelectMatch(match)} onApprove={() => approveMatch.mutate(match.id, { onSuccess: () => showToast('Match genehmigt.'), onError: () => showToast('Genehmigung fehlgeschlagen.', 'error'), })} /> ))} )} {/* Detail Drawer */} Match-Briefing ) }