'use client';
import React, { useState, useRef, useCallback, useMemo } from 'react';
import { m, AnimatePresence } from 'framer-motion';
import { MapPin, CheckCircle2, ArrowUpRight } from 'lucide-react';
import Image from 'next/image';
import { usePathname } from 'next/navigation';
import Link from 'next/link';
import { AnimatedGlossyBorder } from '@/components/ui/AnimatedGlossyBorder';
import { Location, projectLocations } from '@/lib/map-data';
import { standorteLocations } from '@/lib/standorte-data';
import { useLocale, useTranslations } from 'next-intl';
interface Stat {
value: string;
suffix?: string;
label: string;
href?: string;
}
interface InteractiveGermanyMapProps {
badge?: string;
title?: React.ReactNode;
description?: string;
stats?: Stat[];
locations?: Location[];
isHero?: boolean;
hideStandorte?: boolean;
}
const MinorNode = React.memo(({ loc, isActive, onEnter, onLeave }: { loc: Location, isActive: boolean, onEnter: (loc: Location) => void, onLeave: () => void }) => (
onEnter(loc)}
onMouseLeave={onLeave}
onTouchStart={() => onEnter(loc)}
onClick={() => onEnter(loc)}
>
));
MinorNode.displayName = 'MinorNode';
const MajorNode = React.memo(({ loc, isActive, idx, onEnter, onLeave }: { loc: Location, isActive: boolean, idx: number, onEnter: (loc: Location) => void, onLeave: () => void }) => {
const isHQ = loc.type === 'hq';
const isBranch = loc.type === 'branch';
return (
onEnter(loc)}
onMouseLeave={onLeave}
onTouchStart={() => onEnter(loc)}
onClick={() => onEnter(loc)}
>
{(isHQ || isBranch) && (
)}
{(isHQ || isBranch) && }
);
});
MajorNode.displayName = 'MajorNode';
export function InteractiveGermanyMap({
badge,
title,
description,
stats,
locations = projectLocations,
isHero = false,
hideStandorte = false
}: InteractiveGermanyMapProps) {
const [activeLocation, setActiveLocation] = useState(null);
const hoverTimeoutRef = useRef(null);
const handleMouseEnter = useCallback((loc: Location) => {
if (hoverTimeoutRef.current) {
clearTimeout(hoverTimeoutRef.current);
hoverTimeoutRef.current = null;
}
setActiveLocation(loc);
}, []);
const handleMouseLeave = useCallback(() => {
const timeout = setTimeout(() => {
setActiveLocation(null);
}, 200);
hoverTimeoutRef.current = timeout;
}, []);
const pathname = usePathname();
const locale = useLocale();
const t = useTranslations('InteractiveGermanyMap');
const tStandard = useTranslations('StandardPage');
const finalStats = stats || [
{ value: '100', suffix: '%', label: locale === 'en' ? 'Nationwide Reach' : 'Überregionale Reichweite' },
{ value: '3', suffix: '', label: locale === 'en' ? 'Operational Locations' : 'Operative Standorte', href: `/${locale}/standorte` },
];
const finalBadge = badge || tStandard('badge');
const finalTitle = title || (locale === 'en' ? <>Nationwide
in operation for you.> : <>Deutschlandweit
für Sie im Einsatz.>);
const finalDescription = description || (locale === 'en' ? 'From our strategic locations in Guben, Kirchheilingen and Bülstedt, we control and implement complex infrastructure projects nationwide.' : 'Von unseren strategischen Standorten in Guben, Kirchheilingen und Bülstedt steuern und realisieren wir komplexe Infrastrukturprojekte im gesamten Bundesgebiet.');
const finalLocations = useMemo(() => {
if (hideStandorte) return locations;
const base = [...locations];
standorteLocations.forEach(sl => {
if (!base.some(l => l.id === sl.id)) {
base.push(sl as Location);
}
});
return base;
}, [locations, hideStandorte]);
const mapBackground = useMemo(() => (
), [locale]);
return (
{!isHero &&
}
{finalBadge}
{isHero ? (
{finalTitle}
) : (
{finalTitle}
)}
{finalDescription}
{finalStats.map((stat, i) => {
const StatCard = () => (
{stat.value}{stat.suffix}
{stat.label}
{stat.href &&
}
);
return stat.href ? (
) : (
);
})}
{mapBackground}
{finalLocations.filter(l => l.type === 'minor_node').map((loc, idx) => (
))}
{finalLocations.filter(l => l.type !== 'minor_node').map((loc, idx) => (
))}
{activeLocation && (
handleMouseEnter(activeLocation)}
onMouseLeave={handleMouseLeave}
>
{activeLocation.featuredImage && (
)}
{t(`types.${activeLocation.type === 'minor_node' ? 'project' : activeLocation.type}`)}
{activeLocation.name}
{activeLocation.type !== 'minor_node' ? (
{activeLocation.description}
) : (
{t(`descriptions.${['wind','pv','fiber','power','battery'].includes(activeLocation.description || '') ? activeLocation.description : 'default'}`)}
)}
{(activeLocation.details || activeLocation.type === 'minor_node') && (
{activeLocation.type === 'minor_node' ? (
<>
-
{t(`features.${['wind','pv','fiber','power','battery'].includes(activeLocation.description || '') ? activeLocation.description : 'default'}`)}
-
{t('features.method')}
>
) : (
activeLocation.details?.map((detail, i) => (
-
{detail}
))
)}
)}
{activeLocation.href && (activeLocation.type === 'hq' || activeLocation.type === 'branch') && (
e.stopPropagation()}
>
{t('learnMore')}
)}
)}
);
}