import React, { useState, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { MainLayout } from '@/components/layout/MainLayout.tsx'; import PageHeader from '@/components/layout/PageHeader.tsx'; import MatchCard from '@/components/matches/MatchCard.tsx'; import { Container, Stack, Grid, Flex } from '@/components/ui/layout'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card.tsx'; import Button from '@/components/ui/Button.tsx'; import Select from '@/components/ui/Select.tsx'; import Input from '@/components/ui/Input.tsx'; import Badge from '@/components/ui/Badge.tsx'; import ModuleErrorBoundary from '@/components/ui/ModuleErrorBoundary.tsx'; import { MapProvider, useMapUI } from '@/contexts/MapContexts.tsx'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { useTopMatches } from '@/hooks/api/useMatchingAPI.ts'; import { useNavigation } from '@/hooks/useNavigation.tsx'; import { ArrowLeft, Filter, MapPin, TrendingUp } from 'lucide-react'; // Import the extended map component const MatchesMap = React.lazy(() => import('../components/map/MatchesMap.tsx')); interface MatchesMapContentProps {} const MatchesMapContent: React.FC = () => { const { t } = useTranslation(); const navigate = useNavigate(); const { handleBackNavigation, handleFooterNavigate } = useNavigation(); const { isSidebarOpen, setIsSidebarOpen } = useMapUI(); // Match filtering state const [selectedMatch, setSelectedMatch] = useState(null); const [statusFilter, setStatusFilter] = useState('all'); const [minScoreFilter, setMinScoreFilter] = useState(0.5); const [maxDistanceFilter, setMaxDistanceFilter] = useState(50); // Get matches data const { data: matchesData, isLoading } = useTopMatches(100); // Filter matches based on criteria const filteredMatches = useMemo(() => { if (!matchesData?.matches) return []; return matchesData.matches.filter(match => { // Status filter if (statusFilter !== 'all' && match.Status !== statusFilter) { return false; } // Score filter if (match.CompatibilityScore < minScoreFilter) { return false; } // Distance filter if (match.DistanceKm > maxDistanceFilter) { return false; } return true; }); }, [matchesData, statusFilter, minScoreFilter, maxDistanceFilter]); const statusOptions = [ { value: 'all', label: t('matchesMap.allStatuses') }, { value: 'suggested', label: t('matchStatus.suggested') }, { value: 'negotiating', label: t('matchStatus.negotiating') }, { value: 'reserved', label: t('matchStatus.reserved') }, { value: 'contracted', label: t('matchStatus.contracted') }, { value: 'live', label: t('matchStatus.live') }, ]; const selectedMatchData = useMemo(() => { return selectedMatch ? filteredMatches.find(m => m.ID === selectedMatch) : null; }, [selectedMatch, filteredMatches]); const handleViewMatchDetails = (matchId: string) => { navigate(`/matching/${matchId}`); }; const handleMatchSelect = (matchId: string) => { setSelectedMatch(matchId === selectedMatch ? null : matchId); }; return (
{/* Header */}

{t('matchesMap.title')}

{t('matchesMap.subtitle')}

{/* Quick stats */} {filteredMatches.length} {t('matchesMap.matches')} {filteredMatches.filter(m => m.Status === 'live').length} {t('matchesMap.live')}
{/* Sidebar */}
{/* Filters */} {t('matchesMap.filters')}
setMinScoreFilter(Number(e.target.value))} className="w-full" />
{Math.round(minScoreFilter * 100)}%
setMaxDistanceFilter(Number(e.target.value))} className="w-full" />
{maxDistanceFilter} km
{/* Selected Match Details */} {selectedMatchData && ( {t('matchesMap.selectedMatch')} )} {/* Match List */} {t('matchesMap.matches')} {filteredMatches.length} {isLoading ? (
{[...Array(5)].map((_, i) => (
))}
) : filteredMatches.length > 0 ? (
{filteredMatches.slice(0, 20).map((match) => (
handleMatchSelect(match.ID)} >
{t(`matchStatus.${match.Status}`, match.Status)} {match.DistanceKm.toFixed(1)} km
{Math.round(match.CompatibilityScore * 100)}% compatibility
€{match.EconomicValue.toLocaleString()}
))} {filteredMatches.length > 20 && (
)}
) : (

{t('matchesMap.noMatches')}

{t('matchesMap.adjustFilters')}

)}
{/* Map */}
{/* Sidebar Toggle */} {/* Legend */}
{t('matchesMap.legend')}
{t('matchesMap.matchConnection')}
{t('matchesMap.resourceFlow')}
{t('matchesMap.liveMatch')}
); }; const MatchesMapView = () => ( ); export default MatchesMapView;