import { Box, CircularProgress, Typography } from '@mui/material' import { useNavigate } from 'react-router' import { useMatchesByProperty, useApproveMatch } from '../../hooks/useMatches' import { usePropertyById } from '../../hooks/useProperties' import { useCreateReviewTask } from '../../hooks/useReviewQueue' import { useMatchCenterStore } from '../../stores/matchCenterStore' import { useCompareStore } from '../../stores/compareStore' import { useToastStore } from '../../stores/toastStore' import { MatchCardExpanded } from '../match-card/MatchCardExpanded' import { buildMatchCardViewModel } from '../../features/matching/matchCardAdapter' import { MatchCenterEmptyState } from './MatchCenterEmptyState' import { MatchStatusBadge } from './MatchStatusBadge' import type { MatchCardAction } from '../match-card/MatchCardViewModel' import type { VerifiedPortfolioResult } from '../../domain/unifiedResult' export function MatchBriefingPanel() { const navigate = useNavigate() const { selectedPropertyId, selectedNeedId } = useMatchCenterStore() const { addToCompare } = useCompareStore() const approveMatch = useApproveMatch() const createReviewTask = useCreateReviewTask() const showToast = useToastStore((s) => s.showToast) const { data: matches = [], isLoading: matchesLoading } = useMatchesByProperty(selectedPropertyId ?? '') const { data: property = null, isLoading: propLoading } = usePropertyById(selectedPropertyId) if (!selectedPropertyId && !selectedNeedId) return if (selectedPropertyId && !selectedNeedId) return if (!selectedPropertyId && selectedNeedId) return if (matchesLoading || propLoading) { return ( ) } const match = matches.find(m => m.needId === selectedNeedId) ?? null if (!match || !property) return const result: VerifiedPortfolioResult = { resultType: 'VERIFIED_PORTFOLIO', matchId: match.id, needId: match.needId, matchScore: match.matchScore, match, property, } const actions: MatchCardAction[] = [ { id: 'approve', label: 'Genehmigen', actionType: 'APPROVE', variant: 'primary', onClick: () => approveMatch.mutate(match.id, { onSuccess: () => showToast('Match genehmigt.'), onError: () => showToast('Genehmigung fehlgeschlagen.', 'error'), }), }, { id: 'review', label: 'Zur Prüfung', actionType: 'SEND_REVIEW', variant: 'secondary', onClick: () => { createReviewTask.mutate(match.id) }, }, { id: 'compare', label: 'Vergleichen', actionType: 'ADD_COMPARE', variant: 'secondary', onClick: () => { addToCompare(result); navigate('/demand/compare') }, }, { id: 'details', label: 'Details', actionType: 'OPEN_DETAIL', variant: 'secondary', onClick: () => navigate(`/demand/results/${match.id}`), }, ] const vm = buildMatchCardViewModel(result, actions) return ( Match-Briefing ) }